Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / messaging / tests / MessagingContext.cpp
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 <messaging/tests/MessagingContext.h>
19
20 #include <support/CodeUtils.h>
21 #include <support/ErrorStr.h>
22
23 namespace chip {
24 namespace Test {
25
26 CHIP_ERROR MessagingContext::Init(nlTestSuite * suite, TransportMgrBase * transport)
27 {
28     ReturnErrorOnFailure(IOContext::Init(suite));
29
30     mAdmins.Reset();
31
32     chip::Transport::AdminPairingInfo * srcNodeAdmin = mAdmins.AssignAdminId(mSrcAdminId, GetSourceNodeId());
33     VerifyOrReturnError(srcNodeAdmin != nullptr, CHIP_ERROR_NO_MEMORY);
34
35     chip::Transport::AdminPairingInfo * destNodeAdmin = mAdmins.AssignAdminId(mDestAdminId, GetDestinationNodeId());
36     VerifyOrReturnError(destNodeAdmin != nullptr, CHIP_ERROR_NO_MEMORY);
37
38     ReturnErrorOnFailure(mSecureSessionMgr.Init(GetSourceNodeId(), &GetSystemLayer(), transport, &mAdmins));
39
40     ReturnErrorOnFailure(mExchangeManager.Init(&mSecureSessionMgr));
41
42     ReturnErrorOnFailure(mSecureSessionMgr.NewPairing(mPeer, GetDestinationNodeId(), &mPairingLocalToPeer,
43                                                       SecureSessionMgr::PairingDirection::kInitiator, mSrcAdminId));
44
45     return mSecureSessionMgr.NewPairing(mPeer, GetSourceNodeId(), &mPairingPeerToLocal,
46                                         SecureSessionMgr::PairingDirection::kResponder, mDestAdminId);
47 }
48
49 // Shutdown all layers, finalize operations
50 CHIP_ERROR MessagingContext::Shutdown()
51 {
52     mExchangeManager.Shutdown();
53     return IOContext::Shutdown();
54 }
55
56 Messaging::ExchangeContext * MessagingContext::NewExchangeToPeer(Messaging::ExchangeDelegate * delegate)
57 {
58     // TODO: temprary create a SecureSessionHandle from node id, will be fix in PR 3602
59     return mExchangeManager.NewContext({ GetDestinationNodeId(), GetPeerKeyId(), GetAdminId() }, delegate);
60 }
61
62 Messaging::ExchangeContext * MessagingContext::NewExchangeToLocal(Messaging::ExchangeDelegate * delegate)
63 {
64     // TODO: temprary create a SecureSessionHandle from node id, will be fix in PR 3602
65     return mExchangeManager.NewContext({ GetSourceNodeId(), GetLocalKeyId(), GetAdminId() }, delegate);
66 }
67
68 } // namespace Test
69 } // namespace chip