Line data Source code
1 : /* 2 : * 3 : * Copyright (c) 2021 Project CHIP Authors 4 : * 5 : * Licensed under the Apache License, Version 2.0 (the "License"); 6 : * you may not use this file except in compliance with the License. 7 : * You may obtain a copy of the License at 8 : * 9 : * http://www.apache.org/licenses/LICENSE-2.0 10 : * 11 : * Unless required by applicable law or agreed to in writing, software 12 : * distributed under the License is distributed on an "AS IS" BASIS, 13 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 : * See the License for the specific language governing permissions and 15 : * limitations under the License. 16 : */ 17 : 18 : #include <app/CASEClient.h> 19 : 20 : namespace chip { 21 : 22 0 : void CASEClient::SetRemoteMRPIntervals(const ReliableMessageProtocolConfig & remoteMRPConfig) 23 : { 24 0 : mCASESession.SetRemoteMRPConfig(remoteMRPConfig); 25 0 : } 26 : 27 0 : const ReliableMessageProtocolConfig & CASEClient::GetRemoteMRPIntervals() 28 : { 29 0 : return mCASESession.GetRemoteMRPConfig(); 30 : } 31 : 32 0 : CHIP_ERROR CASEClient::EstablishSession(const CASEClientInitParams & params, const ScopedNodeId & peer, 33 : const Transport::PeerAddress & peerAddress, 34 : const ReliableMessageProtocolConfig & remoteMRPConfig, 35 : SessionEstablishmentDelegate * delegate) 36 : { 37 0 : VerifyOrReturnError(params.fabricTable != nullptr, CHIP_ERROR_INVALID_ARGUMENT); 38 : 39 : // Create a UnauthenticatedSession for CASE pairing. 40 0 : Optional<SessionHandle> session = params.sessionManager->CreateUnauthenticatedSession(peerAddress, remoteMRPConfig); 41 0 : VerifyOrReturnError(session.HasValue(), CHIP_ERROR_NO_MEMORY); 42 : 43 : // Allocate the exchange immediately before calling CASESession::EstablishSession. 44 : // 45 : // CASESession::EstablishSession takes ownership of the exchange and will 46 : // free it on error, but can only do this if it is actually called. 47 : // Allocating the exchange context right before calling EstablishSession 48 : // ensures that if allocation succeeds, CASESession has taken ownership. 49 0 : Messaging::ExchangeContext * exchange = params.exchangeMgr->NewContext(session.Value(), &mCASESession); 50 0 : VerifyOrReturnError(exchange != nullptr, CHIP_ERROR_INTERNAL); 51 : 52 0 : mCASESession.SetGroupDataProvider(params.groupDataProvider); 53 0 : ReturnErrorOnFailure(mCASESession.EstablishSession(*params.sessionManager, params.fabricTable, peer, exchange, 54 : params.sessionResumptionStorage, params.certificateValidityPolicy, delegate, 55 : params.mrpLocalConfig)); 56 : 57 0 : return CHIP_NO_ERROR; 58 0 : } 59 : 60 : }; // namespace chip