42
42
#include < lib/support/CodeUtils.h>
43
43
#include < lib/support/ZclString.h>
44
44
#include < platform/CHIPDeviceLayer.h>
45
+ #include < zap-generated/CHIPClusters.h>
45
46
46
47
using namespace chip ;
47
48
using namespace chip ::AppPlatform;
49
+ using namespace chip ::app::Clusters;
48
50
49
51
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE
50
52
class MyUserPrompter : public UserPrompter
@@ -89,9 +91,44 @@ class MyPostCommissioningListener : public PostCommissioningListener
89
91
void CommissioningCompleted (uint16_t vendorId, uint16_t productId, NodeId nodeId, Messaging::ExchangeManager & exchangeMgr,
90
92
SessionHandle & sessionHandle) override
91
93
{
94
+ // read current binding list
95
+ chip::Controller::BindingCluster cluster (exchangeMgr, sessionHandle, kTargetBindingClusterEndpointId );
92
96
93
- ContentAppPlatform::GetInstance ().ManageClientAccess (
94
- exchangeMgr, sessionHandle, vendorId, GetDeviceCommissioner ()->GetNodeId (), OnSuccessResponse, OnFailureResponse);
97
+ cacheContext (vendorId, productId, nodeId, exchangeMgr, sessionHandle);
98
+
99
+ CHIP_ERROR err =
100
+ cluster.ReadAttribute <Binding::Attributes::Binding::TypeInfo>(this , OnReadSuccessResponse, OnReadFailureResponse);
101
+ if (err != CHIP_NO_ERROR)
102
+ {
103
+ ChipLogError (Controller, " Failed in reading binding. Error %s" , ErrorStr (err));
104
+ clearContext ();
105
+ }
106
+ }
107
+
108
+ /* Callback when command results in success */
109
+ static void
110
+ OnReadSuccessResponse (void * context,
111
+ const app::DataModel::DecodableList<Binding::Structs::TargetStruct::DecodableType> & responseData)
112
+ {
113
+ ChipLogProgress (Controller, " OnReadSuccessResponse - Binding Read Successfully" );
114
+
115
+ MyPostCommissioningListener * listener = static_cast <MyPostCommissioningListener *>(context);
116
+ listener->finishTargetConfiguration (responseData);
117
+ }
118
+
119
+ /* Callback when command results in failure */
120
+ static void OnReadFailureResponse (void * context, CHIP_ERROR error)
121
+ {
122
+ ChipLogProgress (Controller, " OnReadFailureResponse - Binding Read Failed" );
123
+
124
+ MyPostCommissioningListener * listener = static_cast <MyPostCommissioningListener *>(context);
125
+ listener->clearContext ();
126
+
127
+ CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController ();
128
+ if (cdc != nullptr )
129
+ {
130
+ cdc->PostCommissioningFailed (error);
131
+ }
95
132
}
96
133
97
134
/* Callback when command results in success */
@@ -115,6 +152,60 @@ class MyPostCommissioningListener : public PostCommissioningListener
115
152
cdc->PostCommissioningFailed (error);
116
153
}
117
154
}
155
+
156
+ void
157
+ finishTargetConfiguration (const app::DataModel::DecodableList<Binding::Structs::TargetStruct::DecodableType> & responseList)
158
+ {
159
+ std::vector<app::Clusters::Binding::Structs::TargetStruct::Type> bindings;
160
+ NodeId localNodeId = GetDeviceCommissioner ()->GetNodeId ();
161
+
162
+ auto iter = responseList.begin ();
163
+ while (iter.Next ())
164
+ {
165
+ auto & binding = iter.GetValue ();
166
+ ChipLogProgress (Controller, " Binding found nodeId=0x" ChipLogFormatX64 " my nodeId=0x" ChipLogFormatX64,
167
+ ChipLogValueX64 (binding.node .ValueOr (0 )), ChipLogValueX64 (localNodeId));
168
+ if (binding.node .ValueOr (0 ) != localNodeId)
169
+ {
170
+ ChipLogProgress (Controller, " Found a binding for a different node, preserving" );
171
+ bindings.push_back (binding);
172
+ }
173
+ else
174
+ {
175
+ ChipLogProgress (Controller, " Found a binding for a matching node, dropping" );
176
+ }
177
+ }
178
+
179
+ Optional<SessionHandle> opt = mSecureSession .Get ();
180
+ SessionHandle & sessionHandle = opt.Value ();
181
+ ContentAppPlatform::GetInstance ().ManageClientAccess (*mExchangeMgr , sessionHandle, mVendorId , mProductId , localNodeId,
182
+ bindings, OnSuccessResponse, OnFailureResponse);
183
+ clearContext ();
184
+ }
185
+
186
+ void cacheContext (uint16_t vendorId, uint16_t productId, NodeId nodeId, Messaging::ExchangeManager & exchangeMgr,
187
+ SessionHandle & sessionHandle)
188
+ {
189
+ mVendorId = vendorId;
190
+ mProductId = productId;
191
+ mNodeId = nodeId;
192
+ mExchangeMgr = &exchangeMgr;
193
+ mSecureSession .ShiftToSession (sessionHandle);
194
+ }
195
+
196
+ void clearContext ()
197
+ {
198
+ mVendorId = 0 ;
199
+ mProductId = 0 ;
200
+ mNodeId = 0 ;
201
+ mExchangeMgr = nullptr ;
202
+ mSecureSession .SessionReleased ();
203
+ }
204
+ uint16_t mVendorId = 0 ;
205
+ uint16_t mProductId = 0 ;
206
+ NodeId mNodeId = 0 ;
207
+ Messaging::ExchangeManager * mExchangeMgr = nullptr ;
208
+ SessionHolder mSecureSession ;
118
209
};
119
210
120
211
MyPostCommissioningListener gMyPostCommissioningListener ;
@@ -407,6 +498,19 @@ Access::Privilege ContentAppFactoryImpl::GetVendorPrivilege(uint16_t vendorId)
407
498
return Access::Privilege::kOperate ;
408
499
}
409
500
501
+ std::list<ClusterId> ContentAppFactoryImpl::GetAllowedClusterListForStaticEndpoint (EndpointId endpointId, uint16_t vendorId,
502
+ uint16_t productId)
503
+ {
504
+ if (endpointId == kLocalVideoPlayerEndpointId )
505
+ {
506
+ return { chip::app::Clusters::Descriptor::Id, chip::app::Clusters::OnOff::Id,
507
+ chip::app::Clusters::WakeOnLan::Id, chip::app::Clusters::MediaPlayback::Id,
508
+ chip::app::Clusters::LowPower::Id, chip::app::Clusters::KeypadInput::Id,
509
+ chip::app::Clusters::ContentLauncher::Id, chip::app::Clusters::AudioOutput::Id };
510
+ }
511
+ return {};
512
+ }
513
+
410
514
} // namespace AppPlatform
411
515
} // namespace chip
412
516
0 commit comments