Skip to content

Commit 4fa28cd

Browse files
committed
Return kUndefinedNodeId if get the NodeID from a group or PASE session.
1 parent ae329ea commit 4fa28cd

File tree

2 files changed

+76
-10
lines changed

2 files changed

+76
-10
lines changed

src/app/clusters/commissioner-control-server/commissioner-control-server.cpp

+30-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@ using chip::Protocols::InteractionModel::Status;
3838

3939
namespace {
4040

41+
NodeId getNodeId(const app::CommandHandler * commandObj)
42+
{
43+
if (nullptr == commandObj || nullptr == commandObj->GetExchangeContext())
44+
{
45+
ChipLogError(Zcl, "Cannot access ExchangeContext of Command Object for Node ID");
46+
return kUndefinedNodeId;
47+
}
48+
49+
if (!commandObj->GetExchangeContext()->HasSessionHandle())
50+
{
51+
ChipLogError(Zcl, "Cannot access session of Command Object for Node ID");
52+
return kUndefinedNodeId;
53+
}
54+
55+
auto descriptor = commandObj->GetExchangeContext()->GetSessionHandle()->GetSubjectDescriptor();
56+
57+
// Return kUndefinedNodeId if get the NodeID from a group or PASE session.
58+
if (descriptor.authMode != Access::AuthMode::kCase)
59+
{
60+
ChipLogError(Zcl, "Cannot get Node ID from non-CASE session of Command Object");
61+
return kUndefinedNodeId;
62+
}
63+
64+
return descriptor.subject;
65+
}
66+
4167
void AddReverseOpenCommissioningWindowResponse(CommandHandler * commandObj, const ConcreteCommandPath & path,
4268
const Clusters::CommissionerControl::CommissioningWindowParams & params)
4369
{
@@ -147,8 +173,7 @@ bool emberAfCommissionerControlClusterRequestCommissioningApprovalCallback(
147173

148174
ChipLogProgress(Zcl, "Received command to request commissioning approval");
149175

150-
auto descriptor = commandObj->GetSubjectDescriptor();
151-
auto sourceNodeId = descriptor.subject;
176+
auto sourceNodeId = getNodeId(commandObj);
152177
auto fabricIndex = commandObj->GetAccessingFabricIndex();
153178
auto requestId = commandData.requestId;
154179
auto vendorId = commandData.vendorId;
@@ -194,8 +219,7 @@ bool emberAfCommissionerControlClusterCommissionNodeCallback(
194219

195220
ChipLogProgress(Zcl, "Received command to commission node");
196221

197-
auto descriptor = commandObj->GetSubjectDescriptor();
198-
auto sourceNodeId = descriptor.subject;
222+
auto sourceNodeId = getNodeId(commandObj);
199223
auto requestId = commandData.requestId;
200224

201225
auto info = std::make_unique<Clusters::CommissionerControl::CommissionNodeInfo>();
@@ -209,8 +233,8 @@ bool emberAfCommissionerControlClusterCommissionNodeCallback(
209233
VerifyOrExit(delegate != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
210234

211235
// Handle commissioning approval request, the ipAddress assigned from commandData need to be stored in
212-
// CommissionerControl::Delegate which ensure that the backing buffer of ipAddress has a valid lifespan until the deferred task
213-
// is executed.
236+
// CommissionerControl::Delegate which ensure that the backing buffer of ipAddress has a valid lifespan
237+
// until the deferred task is executed.
214238
err = delegate->ValidateCommissionNodeCommand(sourceNodeId, requestId, info->params);
215239
SuccessOrExit(err == CHIP_NO_ERROR);
216240

src/app/clusters/commissioner-control-server/commissioner-control-server.h

+46-4
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,55 @@ struct CommissionNodeInfo
5353
class Delegate
5454
{
5555
public:
56-
// Command Delegates
56+
/**
57+
* @brief Handle a commissioning approval request.
58+
*
59+
* This command is sent by a client to request approval for a future CommissionNode call.
60+
* The server SHALL always return SUCCESS to a correctly formatted RequestCommissioningApproval
61+
* command, and then send a CommissioningRequestResult event once the result is ready.
62+
*
63+
* @param request The commissioning approval request to handle.
64+
* @return CHIP_ERROR indicating the success or failure of the operation.
65+
*/
5766
virtual CHIP_ERROR HandleCommissioningApprovalRequest(const CommissioningApprovalRequest & request) = 0;
67+
68+
/**
69+
* @brief Validate a commission node command.
70+
*
71+
* This command is sent by a client to request that the server begins commissioning a previously
72+
* approved request.
73+
*
74+
* The server SHALL return FAILURE if the CommissionNode command is not sent from the same
75+
* NodeId as the RequestCommissioningApproval or if the provided RequestId to CommissionNode
76+
* does not match the value provided to RequestCommissioningApproval.
77+
*
78+
* The validation SHALL fail if the client Node ID is kUndefinedNodeId, such as getting the NodeID from
79+
* a group or PASE session.
80+
*
81+
* @param clientNodeId The NodeId of the client.
82+
* @param requestId The request ID to validate.
83+
* @param outParams Parameters to be used in the commissioning window.
84+
* @return CHIP_ERROR indicating the success or failure of the operation.
85+
*/
5886
virtual CHIP_ERROR ValidateCommissionNodeCommand(NodeId clientNodeId, uint64_t requestId,
59-
CommissioningWindowParams & outParams) = 0;
87+
CommissioningWindowParams & outParams) = 0;
88+
89+
/**
90+
* @brief Reverse the commission node process.
91+
*
92+
* When received within the timeout specified by CommissionNode, the client SHALL open a
93+
* commissioning window on the node which the client called RequestCommissioningApproval to
94+
* have commissioned.
95+
*
96+
* @param params The parameters for the commissioning window.
97+
* @param ipAddress Optional IP address for the commissioning window.
98+
* @param port Optional port for the commissioning window.
99+
* @return CHIP_ERROR indicating the success or failure of the operation.
100+
*/
60101
virtual CHIP_ERROR ReverseCommissionNode(const CommissioningWindowParams & params, const Optional<ByteSpan> & ipAddress,
61-
const Optional<uint16_t> & port) = 0;
62-
virtual ~Delegate() = default;
102+
const Optional<uint16_t> & port) = 0;
103+
104+
virtual ~Delegate() = default;
63105
};
64106

65107
class CommissionerControlServer

0 commit comments

Comments
 (0)