3 * Copyright (c) 2021 Project CHIP Authors
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <messaging/tests/MessagingContext.h>
20 #include <support/CodeUtils.h>
21 #include <support/ErrorStr.h>
26 CHIP_ERROR MessagingContext::Init(nlTestSuite * suite, TransportMgrBase * transport)
28 ReturnErrorOnFailure(IOContext::Init(suite));
32 chip::Transport::AdminPairingInfo * srcNodeAdmin = mAdmins.AssignAdminId(mSrcAdminId, GetSourceNodeId());
33 VerifyOrReturnError(srcNodeAdmin != nullptr, CHIP_ERROR_NO_MEMORY);
35 chip::Transport::AdminPairingInfo * destNodeAdmin = mAdmins.AssignAdminId(mDestAdminId, GetDestinationNodeId());
36 VerifyOrReturnError(destNodeAdmin != nullptr, CHIP_ERROR_NO_MEMORY);
38 ReturnErrorOnFailure(mSecureSessionMgr.Init(GetSourceNodeId(), &GetSystemLayer(), transport, &mAdmins));
40 ReturnErrorOnFailure(mExchangeManager.Init(&mSecureSessionMgr));
42 ReturnErrorOnFailure(mSecureSessionMgr.NewPairing(mPeer, GetDestinationNodeId(), &mPairingLocalToPeer,
43 SecureSessionMgr::PairingDirection::kInitiator, mSrcAdminId));
45 return mSecureSessionMgr.NewPairing(mPeer, GetSourceNodeId(), &mPairingPeerToLocal,
46 SecureSessionMgr::PairingDirection::kResponder, mDestAdminId);
49 // Shutdown all layers, finalize operations
50 CHIP_ERROR MessagingContext::Shutdown()
52 mExchangeManager.Shutdown();
53 return IOContext::Shutdown();
56 Messaging::ExchangeContext * MessagingContext::NewExchangeToPeer(Messaging::ExchangeDelegate * delegate)
58 // TODO: temprary create a SecureSessionHandle from node id, will be fix in PR 3602
59 return mExchangeManager.NewContext({ GetDestinationNodeId(), GetPeerKeyId(), GetAdminId() }, delegate);
62 Messaging::ExchangeContext * MessagingContext::NewExchangeToLocal(Messaging::ExchangeDelegate * delegate)
64 // TODO: temprary create a SecureSessionHandle from node id, will be fix in PR 3602
65 return mExchangeManager.NewContext({ GetSourceNodeId(), GetLocalKeyId(), GetAdminId() }, delegate);