This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mctp_wrapper.cpp
163 lines (138 loc) · 5.29 KB
/
mctp_wrapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
// Copyright (c) 2021 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#include "mctp_wrapper.hpp"
#include "mctp_impl.hpp"
#include <boost/algorithm/string.hpp>
#include <boost/container/flat_map.hpp>
#include <memory>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/bus/match.hpp>
#include <unordered_set>
using namespace mctpw;
template <typename T1, typename T2>
using DictType = boost::container::flat_map<T1, T2>;
using MctpPropertiesVariantType =
std::variant<uint16_t, int16_t, int32_t, uint32_t, bool, std::string,
uint8_t, std::vector<uint8_t>>;
MCTPConfiguration::MCTPConfiguration(MessageType msgType, BindingType binding) :
type(msgType), bindingType(binding)
{
}
MCTPConfiguration::MCTPConfiguration(MessageType msgType, BindingType binding,
uint16_t vid) :
type(msgType),
bindingType(binding)
{
if (MessageType::vdpci != msgType)
{
throw std::invalid_argument("MsgType expected VDPCI");
}
setVendorId(vid);
}
MCTPConfiguration::MCTPConfiguration(MessageType msgType, BindingType binding,
uint16_t vid, uint16_t vendorMsgType,
uint16_t vendorMsgTypeMask) :
MCTPConfiguration(msgType, binding, vid)
{
setVendorMessageType(vendorMsgType, vendorMsgTypeMask);
}
MCTPWrapper::MCTPWrapper(boost::asio::io_context& ioContext,
const MCTPConfiguration& configIn,
const ReconfigurationCallback& networkChangeCb,
const ReceiveMessageCallback& rxCb) :
config(configIn),
pimpl(
std::make_unique<MCTPImpl>(ioContext, configIn, networkChangeCb, rxCb))
{
}
MCTPWrapper::MCTPWrapper(std::shared_ptr<sdbusplus::asio::connection> conn,
const MCTPConfiguration& configIn,
const ReconfigurationCallback& networkChangeCb,
const ReceiveMessageCallback& rxCb) :
config(configIn),
pimpl(std::make_unique<MCTPImpl>(conn, configIn, networkChangeCb, rxCb))
{
}
MCTPWrapper::~MCTPWrapper() noexcept = default;
void MCTPWrapper::detectMctpEndpointsAsync(StatusCallback&& registerCB)
{
pimpl->detectMctpEndpointsAsync(std::forward<StatusCallback>(registerCB));
}
boost::system::error_code
MCTPWrapper::detectMctpEndpoints(boost::asio::yield_context yield)
{
boost::system::error_code ec =
boost::system::errc::make_error_code(boost::system::errc::success);
ec = pimpl->detectMctpEndpoints(yield);
return ec;
}
void MCTPWrapper::sendReceiveAsync(ReceiveCallback callback, eid_t dstEId,
const ByteArray& request,
std::chrono::milliseconds timeout)
{
pimpl->sendReceiveAsync(callback, dstEId, request, timeout);
}
std::pair<boost::system::error_code, ByteArray>
MCTPWrapper::sendReceiveYield(boost::asio::yield_context yield,
eid_t dstEId, const ByteArray& request,
std::chrono::milliseconds timeout)
{
auto receiveResult =
pimpl->sendReceiveYield(yield, dstEId, request, timeout);
return receiveResult;
}
std::pair<boost::system::error_code, ByteArray>
MCTPWrapper::sendReceiveBlocked(eid_t dstEId, const ByteArray& request,
std::chrono::milliseconds timeout)
{
return pimpl->sendReceiveBlocked(dstEId, request, timeout);
}
void MCTPWrapper::sendAsync(const SendCallback& callback, const eid_t dstEId,
const uint8_t msgTag, const bool tagOwner,
const ByteArray& request)
{
pimpl->sendAsync(callback, dstEId, msgTag, tagOwner, request);
}
std::pair<boost::system::error_code, int>
MCTPWrapper::sendYield(boost::asio::yield_context& yield,
const eid_t dstEId, const uint8_t msgTag,
const bool tagOwner, const ByteArray& request)
{
return pimpl->sendYield(yield, dstEId, msgTag, tagOwner, request);
}
const MCTPWrapper::EndpointMap& MCTPWrapper::getEndpointMap()
{
return pimpl->getEndpointMap();
}
void MCTPWrapper::triggerMCTPDeviceDiscovery(const eid_t dstEId)
{
pimpl->triggerMCTPDeviceDiscovery(dstEId);
}
int MCTPWrapper::reserveBandwidth(boost::asio::yield_context yield,
const eid_t dstEId, const uint16_t timeout)
{
return pimpl->reserveBandwidth(yield, dstEId, timeout);
}
int MCTPWrapper::releaseBandwidth(boost::asio::yield_context yield,
const eid_t dstEId)
{
return pimpl->releaseBandwidth(yield, dstEId);
}
std::optional<std::string> MCTPWrapper::getDeviceLocation(const eid_t eid)
{
return pimpl->getDeviceLocation(eid);
}