Skip to content

Commit 9cfffb8

Browse files
authored
Add WebRTCTransportRequestor cluster support in dynamic server (#38153)
1 parent 0fcd674 commit 9cfffb8

File tree

3 files changed

+112
-29
lines changed

3 files changed

+112
-29
lines changed

src/app/dynamic_server/AccessControl.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ using namespace chip::Access;
3131
using namespace chip::app::Clusters;
3232

3333
namespace {
34-
// TODO: Maybe consider making this configurable? See also
35-
// DynamicDispatch.cpp.
36-
constexpr EndpointId kSupportedEndpoint = 0;
3734

3835
class DeviceTypeResolver : public chip::Access::DynamicProviderDeviceTypeResolver
3936
{
@@ -50,9 +47,17 @@ class AccessControlDelegate : public Access::AccessControl::Delegate
5047
CHIP_ERROR Check(const SubjectDescriptor & subjectDescriptor, const RequestPath & requestPath,
5148
Privilege requestPrivilege) override
5249
{
53-
if (requestPath.endpoint != kSupportedEndpoint || requestPath.cluster != OtaSoftwareUpdateProvider::Id)
50+
// Check for OTA Software Update Provider endpoint
51+
bool isOtaEndpoint =
52+
(requestPath.endpoint == kOtaProviderDynamicEndpointId && requestPath.cluster == OtaSoftwareUpdateProvider::Id);
53+
54+
// Check for WebRTC Transport Requestor endpoint
55+
bool isWebRtcEndpoint =
56+
(requestPath.endpoint == kWebRTCRequesterDynamicEndpointId && requestPath.cluster == WebRTCTransportRequestor::Id);
57+
58+
// Only allow these specific endpoints
59+
if (!isOtaEndpoint && !isWebRtcEndpoint)
5460
{
55-
// We only allow access to OTA software update provider.
5661
return CHIP_ERROR_ACCESS_DENIED;
5762
}
5863

src/app/dynamic_server/AccessControl.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@
1515
*/
1616
#pragma once
1717

18-
// Experimental API for Access Control
18+
#include <lib/core/DataModelTypes.h>
19+
20+
constexpr chip::EndpointId kOtaProviderDynamicEndpointId = 0;
21+
constexpr chip::EndpointId kWebRTCRequesterDynamicEndpointId = 1;
1922

2023
namespace chip {
2124
namespace app {
2225
namespace dynamic_server {
26+
2327
/**
2428
* Initialize the access control module. Must be called on the Matter task
2529
* queue.
2630
*/
2731
void InitAccessControl();
32+
2833
} // namespace dynamic_server
2934
} // namespace app
3035
} // namespace chip

src/app/dynamic_server/DynamicDispatcher.cpp

+96-23
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18+
19+
#include "AccessControl.h"
20+
1821
#include <access/SubjectDescriptor.h>
1922
#include <app-common/zap-generated/callback.h>
2023
#include <app-common/zap-generated/cluster-objects.h>
@@ -52,10 +55,6 @@ using namespace chip::app::Clusters;
5255

5356
namespace {
5457

55-
// TODO: Maybe consider making this configurable? See also
56-
// AccessControl.cpp.
57-
constexpr EndpointId kSupportedEndpoint = 0;
58-
5958
DataVersion gMockDataVersion = 0;
6059

6160
} // anonymous namespace
@@ -118,15 +117,18 @@ void DispatchSingleClusterCommand(const ConcreteCommandPath & aPath, TLV::TLVRea
118117
} // namespace chip
119118

120119
/**
121-
* Called by the OTA provider cluster server to determine an index
122-
* into its array.
120+
* Returns the index of the given endpoint in the list of all endpoints that might support the given cluster server.
123121
*/
124122
uint16_t emberAfGetClusterServerEndpointIndex(EndpointId endpoint, ClusterId cluster, uint16_t fixedClusterServerEndpointCount)
125123
{
126-
if (endpoint == kSupportedEndpoint && cluster == OtaSoftwareUpdateProvider::Id)
124+
if (endpoint == kOtaProviderDynamicEndpointId && cluster == OtaSoftwareUpdateProvider::Id)
127125
{
128126
return 0;
129127
}
128+
else if (endpoint == kWebRTCRequesterDynamicEndpointId && cluster == WebRTCTransportRequestor::Id)
129+
{
130+
return 1;
131+
}
130132

131133
return UINT16_MAX;
132134
}
@@ -145,31 +147,47 @@ uint16_t emberAfGetServerAttributeCount(EndpointId endpoint, ClusterId cluster)
145147

146148
uint16_t emberAfEndpointCount(void)
147149
{
148-
return 1;
150+
return 2;
149151
}
150152

151153
uint16_t emberAfIndexFromEndpoint(EndpointId endpoint)
152154
{
153-
if (endpoint == kSupportedEndpoint)
155+
if (endpoint == kOtaProviderDynamicEndpointId)
154156
{
155157
return 0;
156158
}
159+
else if (endpoint == kWebRTCRequesterDynamicEndpointId)
160+
{
161+
return 1;
162+
}
157163

158164
return UINT16_MAX;
159165
}
160166

161167
EndpointId emberAfEndpointFromIndex(uint16_t index)
162168
{
163-
// Index must be valid here, so 0.
164-
return kSupportedEndpoint;
169+
if (index == 0)
170+
{
171+
return kOtaProviderDynamicEndpointId;
172+
}
173+
else if (index == 1)
174+
{
175+
return kWebRTCRequesterDynamicEndpointId;
176+
}
177+
178+
return UINT16_MAX;
165179
}
166180

167181
Optional<ClusterId> emberAfGetNthClusterId(EndpointId endpoint, uint8_t n, bool server)
168182
{
169-
if (endpoint == kSupportedEndpoint && n == 0 && server)
183+
if (endpoint == kOtaProviderDynamicEndpointId && n == 0 && server)
170184
{
171185
return MakeOptional(OtaSoftwareUpdateProvider::Id);
172186
}
187+
else if (endpoint == kWebRTCRequesterDynamicEndpointId && n == 0 && server)
188+
{
189+
return MakeOptional(WebRTCTransportRequestor::Id);
190+
}
173191

174192
return NullOptional;
175193
}
@@ -186,7 +204,12 @@ bool emberAfContainsAttribute(chip::EndpointId endpoint, chip::ClusterId cluster
186204

187205
uint8_t emberAfClusterCount(EndpointId endpoint, bool server)
188206
{
189-
if (endpoint == kSupportedEndpoint && server)
207+
if (endpoint == kOtaProviderDynamicEndpointId && server)
208+
{
209+
return 1;
210+
}
211+
212+
if (endpoint == kWebRTCRequesterDynamicEndpointId && server)
190213
{
191214
return 1;
192215
}
@@ -209,7 +232,14 @@ Optional<AttributeId> emberAfGetServerAttributeIdByIndex(EndpointId endpoint, Cl
209232

210233
uint8_t emberAfClusterIndex(EndpointId endpoint, ClusterId clusterId, EmberAfClusterMask mask)
211234
{
212-
if (endpoint == kSupportedEndpoint && clusterId == OtaSoftwareUpdateProvider::Id && (mask & MATTER_CLUSTER_FLAG_SERVER))
235+
if (endpoint == kOtaProviderDynamicEndpointId && clusterId == OtaSoftwareUpdateProvider::Id &&
236+
(mask & MATTER_CLUSTER_FLAG_SERVER))
237+
{
238+
return 0;
239+
}
240+
241+
if (endpoint == kWebRTCRequesterDynamicEndpointId && clusterId == WebRTCTransportRequestor::Id &&
242+
(mask & MATTER_CLUSTER_FLAG_SERVER))
213243
{
214244
return 0;
215245
}
@@ -223,43 +253,81 @@ bool emberAfEndpointIndexIsEnabled(uint16_t index)
223253
}
224254

225255
namespace {
226-
const CommandId acceptedCommands[] = { Clusters::OtaSoftwareUpdateProvider::Commands::QueryImage::Id,
227-
Clusters::OtaSoftwareUpdateProvider::Commands::ApplyUpdateRequest::Id,
228-
Clusters::OtaSoftwareUpdateProvider::Commands::NotifyUpdateApplied::Id, kInvalidCommandId };
229-
const CommandId generatedCommands[] = { Clusters::OtaSoftwareUpdateProvider::Commands::QueryImageResponse::Id,
230-
Clusters::OtaSoftwareUpdateProvider::Commands::ApplyUpdateResponse::Id, kInvalidCommandId };
256+
257+
const CommandId acceptedOtaProviderCommands[] = { Clusters::OtaSoftwareUpdateProvider::Commands::QueryImage::Id,
258+
Clusters::OtaSoftwareUpdateProvider::Commands::ApplyUpdateRequest::Id,
259+
Clusters::OtaSoftwareUpdateProvider::Commands::NotifyUpdateApplied::Id,
260+
kInvalidCommandId };
261+
262+
const CommandId generatedOtaProviderCommands[] = { Clusters::OtaSoftwareUpdateProvider::Commands::QueryImageResponse::Id,
263+
Clusters::OtaSoftwareUpdateProvider::Commands::ApplyUpdateResponse::Id,
264+
kInvalidCommandId };
265+
231266
const EmberAfCluster otaProviderCluster{
232267
.clusterId = Clusters::OtaSoftwareUpdateProvider::Id,
233268
.attributes = nullptr,
234269
.attributeCount = 0,
235270
.clusterSize = 0,
236271
.mask = MATTER_CLUSTER_FLAG_SERVER,
237272
.functions = nullptr,
238-
.acceptedCommandList = acceptedCommands,
239-
.generatedCommandList = generatedCommands,
273+
.acceptedCommandList = acceptedOtaProviderCommands,
274+
.generatedCommandList = generatedOtaProviderCommands,
240275
.eventList = nullptr,
241276
.eventCount = 0,
242277
};
278+
243279
const EmberAfEndpointType otaProviderEndpoint{ .cluster = &otaProviderCluster, .clusterCount = 1, .endpointSize = 0 };
280+
281+
const CommandId acceptedWebRTCRequestorCommands[] = { Clusters::WebRTCTransportRequestor::Commands::Offer::Id,
282+
Clusters::WebRTCTransportRequestor::Commands::Answer::Id,
283+
Clusters::WebRTCTransportRequestor::Commands::ICECandidates::Id,
284+
Clusters::WebRTCTransportRequestor::Commands::End::Id, kInvalidCommandId };
285+
286+
const CommandId generatedWebRTCRequestorCommands[] = { kInvalidCommandId };
287+
288+
const EmberAfCluster webRTCReqeustorCluster{
289+
.clusterId = Clusters::WebRTCTransportRequestor::Id,
290+
.attributes = nullptr,
291+
.attributeCount = 0,
292+
.clusterSize = 0,
293+
.mask = MATTER_CLUSTER_FLAG_SERVER,
294+
.functions = nullptr,
295+
.acceptedCommandList = acceptedWebRTCRequestorCommands,
296+
.generatedCommandList = generatedWebRTCRequestorCommands,
297+
.eventList = nullptr,
298+
.eventCount = 0,
299+
};
300+
301+
const EmberAfEndpointType webRTCRequestorEndpoint{ .cluster = &webRTCReqeustorCluster, .clusterCount = 1, .endpointSize = 0 };
302+
244303
} // namespace
245304

246305
const EmberAfEndpointType * emberAfFindEndpointType(EndpointId endpoint)
247306
{
248-
if (endpoint == kSupportedEndpoint)
307+
if (endpoint == kOtaProviderDynamicEndpointId)
249308
{
250309
return &otaProviderEndpoint;
251310
}
311+
else if (endpoint == kWebRTCRequesterDynamicEndpointId)
312+
{
313+
return &webRTCRequestorEndpoint;
314+
}
252315

253316
return nullptr;
254317
}
255318

256319
const EmberAfCluster * emberAfFindServerCluster(EndpointId endpoint, ClusterId cluster)
257320
{
258-
if (endpoint == kSupportedEndpoint && cluster == Clusters::OtaSoftwareUpdateProvider::Id)
321+
if (endpoint == kOtaProviderDynamicEndpointId && cluster == Clusters::OtaSoftwareUpdateProvider::Id)
259322
{
260323
return &otaProviderCluster;
261324
}
262325

326+
if (endpoint == kWebRTCRequesterDynamicEndpointId && cluster == Clusters::WebRTCTransportRequestor::Id)
327+
{
328+
return &webRTCReqeustorCluster;
329+
}
330+
263331
return nullptr;
264332
}
265333

@@ -341,6 +409,11 @@ const EmberAfCluster * emberAfFindClusterInType(const EmberAfEndpointType * endp
341409
return &otaProviderCluster;
342410
}
343411

412+
if ((endpointType == &webRTCRequestorEndpoint) && (clusterId == Clusters::WebRTCTransportRequestor::Id))
413+
{
414+
return &webRTCReqeustorCluster;
415+
}
416+
344417
return nullptr;
345418
}
346419

0 commit comments

Comments
 (0)