@@ -38,6 +38,32 @@ using chip::Protocols::InteractionModel::Status;
38
38
39
39
namespace {
40
40
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
+
41
67
void AddReverseOpenCommissioningWindowResponse (CommandHandler * commandObj, const ConcreteCommandPath & path,
42
68
const Clusters::CommissionerControl::CommissioningWindowParams & params)
43
69
{
@@ -147,8 +173,7 @@ bool emberAfCommissionerControlClusterRequestCommissioningApprovalCallback(
147
173
148
174
ChipLogProgress (Zcl, " Received command to request commissioning approval" );
149
175
150
- auto descriptor = commandObj->GetSubjectDescriptor ();
151
- auto sourceNodeId = descriptor.subject ;
176
+ auto sourceNodeId = getNodeId (commandObj);
152
177
auto fabricIndex = commandObj->GetAccessingFabricIndex ();
153
178
auto requestId = commandData.requestId ;
154
179
auto vendorId = commandData.vendorId ;
@@ -194,8 +219,7 @@ bool emberAfCommissionerControlClusterCommissionNodeCallback(
194
219
195
220
ChipLogProgress (Zcl, " Received command to commission node" );
196
221
197
- auto descriptor = commandObj->GetSubjectDescriptor ();
198
- auto sourceNodeId = descriptor.subject ;
222
+ auto sourceNodeId = getNodeId (commandObj);
199
223
auto requestId = commandData.requestId ;
200
224
201
225
auto info = std::make_unique<Clusters::CommissionerControl::CommissionNodeInfo>();
@@ -209,8 +233,8 @@ bool emberAfCommissionerControlClusterCommissionNodeCallback(
209
233
VerifyOrExit (delegate != nullptr , err = CHIP_ERROR_INCORRECT_STATE);
210
234
211
235
// 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.
214
238
err = delegate->ValidateCommissionNodeCommand (sourceNodeId, requestId, info->params );
215
239
SuccessOrExit (err == CHIP_NO_ERROR);
216
240
0 commit comments