@@ -241,7 +241,104 @@ CHIP_ERROR PairingSession::DecodeMRPParametersIfPresent(TLV::Tag expectedTag, TL
241
241
}
242
242
return err;
243
243
}
244
+ CHIP_ERROR PairingSession::DecodeMRPParametersIfPresent (TLV::Tag expectedTag, TLV::ContiguousBufferTLVReader & tlvReader,
245
+ SessionParameters & sessionParameters)
246
+ {
247
+ CHIP_ERROR err = CHIP_NO_ERROR;
248
+
249
+ // The MRP parameters are optional.
250
+ if (tlvReader.GetTag () != expectedTag)
251
+ {
252
+ return CHIP_NO_ERROR;
253
+ }
254
+
255
+ TLV::TLVType containerType = TLV::kTLVType_Structure ;
256
+ ReturnErrorOnFailure (tlvReader.EnterContainer (containerType));
257
+
258
+ ReturnErrorOnFailure (tlvReader.Next ());
259
+
260
+ ChipLogDetail (SecureChannel, " Found MRP parameters in the message" );
261
+
262
+ // All TLV elements in the structure are optional. If the first element is present, process it and move
263
+ // the TLV reader to the next element.
264
+ if (TLV::TagNumFromTag (tlvReader.GetTag ()) == SessionParameters::Tag::kSessionIdleInterval )
265
+ {
266
+ uint32_t idleRetransTimeout;
267
+ ReturnErrorOnFailure (tlvReader.Get (idleRetransTimeout));
268
+ sessionParameters.SetMRPIdleRetransTimeout (System::Clock::Milliseconds32 (idleRetransTimeout));
269
+
270
+ // The next element is optional. If it's not present, return CHIP_NO_ERROR.
271
+ SuccessOrExit (err = tlvReader.Next ());
272
+ }
273
+
274
+ if (TLV::TagNumFromTag (tlvReader.GetTag ()) == SessionParameters::Tag::kSessionActiveInterval )
275
+ {
276
+ uint32_t activeRetransTimeout;
277
+ ReturnErrorOnFailure (tlvReader.Get (activeRetransTimeout));
278
+ sessionParameters.SetMRPActiveRetransTimeout (System::Clock::Milliseconds32 (activeRetransTimeout));
279
+
280
+ // The next element is optional. If it's not present, return CHIP_NO_ERROR.
281
+ SuccessOrExit (err = tlvReader.Next ());
282
+ }
283
+
284
+ if (TLV::TagNumFromTag (tlvReader.GetTag ()) == SessionParameters::Tag::kSessionActiveThreshold )
285
+ {
286
+ uint16_t activeThresholdTime;
287
+ ReturnErrorOnFailure (tlvReader.Get (activeThresholdTime));
288
+ sessionParameters.SetMRPActiveThresholdTime (System::Clock::Milliseconds16 (activeThresholdTime));
289
+
290
+ // The next element is optional. If it's not present, return CHIP_NO_ERROR.
291
+ SuccessOrExit (err = tlvReader.Next ());
292
+ }
244
293
294
+ if (TLV::TagNumFromTag (tlvReader.GetTag ()) == SessionParameters::Tag::kDataModelRevision )
295
+ {
296
+ uint16_t dataModelRevision;
297
+ ReturnErrorOnFailure (tlvReader.Get (dataModelRevision));
298
+ sessionParameters.SetDataModelRevision (dataModelRevision);
299
+
300
+ // The next element is optional. If it's not present, return CHIP_NO_ERROR.
301
+ SuccessOrExit (err = tlvReader.Next ());
302
+ }
303
+
304
+ if (TLV::TagNumFromTag (tlvReader.GetTag ()) == SessionParameters::Tag::kInteractionModelRevision )
305
+ {
306
+ uint16_t interactionModelRevision;
307
+ ReturnErrorOnFailure (tlvReader.Get (interactionModelRevision));
308
+ sessionParameters.SetInteractionModelRevision (interactionModelRevision);
309
+
310
+ // The next element is optional. If it's not present, return CHIP_NO_ERROR.
311
+ SuccessOrExit (err = tlvReader.Next ());
312
+ }
313
+
314
+ if (TLV::TagNumFromTag (tlvReader.GetTag ()) == SessionParameters::Tag::kSpecificationVersion )
315
+ {
316
+ uint32_t specificationVersion;
317
+ ReturnErrorOnFailure (tlvReader.Get (specificationVersion));
318
+ sessionParameters.SetSpecificationVersion (specificationVersion);
319
+
320
+ // The next element is optional. If it's not present, return CHIP_NO_ERROR.
321
+ SuccessOrExit (err = tlvReader.Next ());
322
+ }
323
+
324
+ if (TLV::TagNumFromTag (tlvReader.GetTag ()) == SessionParameters::Tag::kMaxPathsPerInvoke )
325
+ {
326
+ uint16_t maxPathsPerInvoke;
327
+ ReturnErrorOnFailure (tlvReader.Get (maxPathsPerInvoke));
328
+ sessionParameters.SetMaxPathsPerInvoke (maxPathsPerInvoke);
329
+
330
+ // The next element is optional. If it's not present, return CHIP_NO_ERROR.
331
+ SuccessOrExit (err = tlvReader.Next ());
332
+ }
333
+
334
+ // Future proofing - Don't error out if there are other tags
335
+ exit :
336
+ if (err == CHIP_END_OF_TLV)
337
+ {
338
+ return tlvReader.ExitContainer (containerType);
339
+ }
340
+ return err;
341
+ }
245
342
bool PairingSession::IsSessionEstablishmentInProgress ()
246
343
{
247
344
if (!mSecureSessionHolder )
0 commit comments