blob: 4c931dfffa4cf6fd54049f9aff9a3f95b659f8d8 [file] [log] [blame]
AppaRao Puli071f3f22018-05-24 16:45:30 +05301/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17#include <host-ipmid/ipmid-api.h>
18
19#include <string>
20
21namespace ipmi
22{
23
24static constexpr uint8_t maxIpmiChannels = 16;
25
26// IPMI return codes specific to channel
27enum ipmi_channel_return_codes
28{
29 IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL = 0x82,
30 IPMI_CC_ACCESS_MODE_NOT_SUPPORTED_FOR_CHANEL = 0x83
31};
32
33// IPMI Spec: Channel Protocol Type
34enum class EChannelProtocolType : uint8_t
35{
36 na = 0x00,
37 ipmbV10 = 0x01,
38 icmbV11 = 0x02,
39 reserved = 0x03,
40 ipmiSmbus = 0x04,
41 kcs = 0x05,
42 smic = 0x06,
43 bt10 = 0x07,
44 bt15 = 0x08,
45 tMode = 0x09,
46 oem = 0x1C,
47};
48
49// IPMI Spec: Channel Medium Type
50enum class EChannelMediumType : uint8_t
51{
52 reserved = 0x00,
53 ipmb = 0x01,
54 icmbV10 = 0x02,
55 icmbV09 = 0x03,
56 lan8032 = 0x04,
57 serial = 0x05,
58 otherLan = 0x06,
59 pciSmbus = 0x07,
60 smbusV11 = 0x08,
61 smbusV20 = 0x09,
62 usbV1x = 0x0A,
63 usbV2x = 0x0B,
64 systemInterface = 0x0C,
65 oem = 0x60,
66 unknown = 0x82,
67};
68
69// IPMI Spec: Channel Session Type
70enum class EChannelSessSupported : uint8_t
71{
72 none = 0,
73 single = 1,
74 multi = 2,
75 any = 3,
76};
77
78// IPMI Spec: Channel Access Mode
79enum class EChannelAccessMode : uint8_t
80{
81 disabled = 0,
82 preboot = 1,
83 alwaysAvail = 2,
84 shared = 3,
85};
86
87// IPMI Spec 2.0 : Authentication Types
88enum class EAuthType : uint8_t
89{
90 none = (1 << 0x0),
91 md2 = (1 << 0x1),
92 md5 = (1 << 0x2),
93 reserved = (1 << 0x3),
94 straightPasswd = (1 << 0x4),
95 oem = (1 << 0x5),
96};
97
98// IPMI Spec: Access mode for channel access set/get
99typedef enum
100{
101 doNotSet = 0x00,
102 nvData = 0x01,
103 activeData = 0x02,
104 reserved = 0x03,
105} EChannelActionType;
106
107enum AccessSetFlag
108{
109 setAccessMode = (1 << 0),
110 setUserAuthEnabled = (1 << 1),
111 setMsgAuthEnabled = (1 << 2),
112 setAlertingEnabled = (1 << 3),
113 setPrivLimit = (1 << 4),
114};
115
116// Struct to store channel access data
117struct ChannelAccess
118{
119 uint8_t accessMode;
120 bool userAuthDisabled;
121 bool perMsgAuthDisabled;
122 bool alertingDisabled;
123 uint8_t privLimit;
124};
125
126// Struct store channel info data
127struct ChannelInfo
128{
129 uint8_t mediumType;
130 uint8_t protocolType;
131 uint8_t sessionSupported;
132 bool isIpmi; // Is session IPMI
133 // This is used in Get LAN Configuration parameter.
134 // This holds the supported AuthTypes for a given channel.
135 uint8_t authTypeSupported;
136};
137
138/** @brief determines valid channel
139 *
140 * @param[in] chNum- channel number
141 *
142 * @return true if valid, false otherwise
143 */
144bool isValidChannel(const uint8_t& chNum);
145
146/** @brief determines whether channel device exist
147 *
148 * @param[in] chNum - channel number
149 *
150 * @return true if valid, false otherwise
151 */
152bool doesDeviceExist(const uint8_t& chNum);
153
154/** @brief determines whether privilege limit is valid
155 *
156 * @param[in] privLimit - Privilege limit
157 *
158 * @return true if valid, false otherwise
159 */
160bool isValidPrivLimit(const uint8_t& privLimit);
161
162/** @brief determines whether access mode is valid
163 *
164 * @param[in] accessMode - Access mode
165 *
166 * @return true if valid, false otherwise
167 */
168bool isValidAccessMode(const uint8_t& accessMode);
169
170/** @brief determines valid authentication type based on channel number
171 *
172 * @param[in] chNum - channel number
173 * @param[in] authType - authentication type
174 *
175 * @return true if valid, false otherwise
176 */
177bool isValidAuthType(const uint8_t& chNum, const EAuthType& authType);
178
179/** @brief determines supported session type of a channel
180 *
181 * @param[in] chNum - channel number
182 *
183 * @return EChannelSessSupported - supported session type
184 */
185EChannelSessSupported getChannelSessionSupport(const uint8_t& chNum);
186
187/** @brief determines number of active sessions on a channel
188 *
189 * @param[in] chNum - channel number
190 *
191 * @return numer of active sessions
192 */
193int getChannelActiveSessions(const uint8_t& chNum);
194
195/** @brief initializes channel management
196 *
197 * @return IPMI_CC_OK for success, others for failure.
198 */
199ipmi_ret_t ipmiChannelInit();
200
201/** @brief provides channel info details
202 *
203 * @param[in] chNum - channel number
204 * @param[out] chInfo - channel info details
205 *
206 * @return IPMI_CC_OK for success, others for failure.
207 */
208ipmi_ret_t getChannelInfo(const uint8_t& chNum, ChannelInfo& chInfo);
209
210/** @brief provides channel access data
211 *
212 * @param[in] chNum - channel number
213 * @param[out] chAccessData -channel access data
214 *
215 * @return IPMI_CC_OK for success, others for failure.
216 */
217ipmi_ret_t getChannelAccessData(const uint8_t& chNum,
218 ChannelAccess& chAccessData);
219
220/** @brief to set channel access data
221 *
222 * @param[in] chNum - channel number
223 * @param[in] chAccessData - channel access data
224 * @param[in] setFlag - flag to indicate updatable fields
225 *
226 * @return IPMI_CC_OK for success, others for failure.
227 */
228ipmi_ret_t setChannelAccessData(const uint8_t& chNum,
229 const ChannelAccess& chAccessData,
230 const uint8_t& setFlag);
231
232/** @brief to get channel access data persistent data
233 *
234 * @param[in] chNum - channel number
235 * @param[out] chAccessData - channel access data
236 *
237 * @return IPMI_CC_OK for success, others for failure.
238 */
239ipmi_ret_t getChannelAccessPersistData(const uint8_t& chNum,
240 ChannelAccess& chAccessData);
241
242/** @brief to set channel access data persistent data
243 *
244 * @param[in] chNum - channel number
245 * @param[in] chAccessData - channel access data
246 * @param[in] setFlag - flag to indicate updatable fields
247 *
248 * @return IPMI_CC_OK for success, others for failure.
249 */
250ipmi_ret_t setChannelAccessPersistData(const uint8_t& chNum,
251 const ChannelAccess& chAccessData,
252 const uint8_t& setFlag);
253
254/** @brief provides supported authentication type for the channel
255 *
256 * @param[in] chNum - channel number
257 * @param[out] authTypeSupported - supported authentication type
258 *
259 * @return IPMI_CC_OK for success, others for failure.
260 */
261ipmi_ret_t getChannelAuthTypeSupported(const uint8_t& chNum,
262 uint8_t& authTypeSupported);
263
264/** @brief provides enabled authentication type for the channel
265 *
266 * @param[in] chNum - channel number
267 * @param[in] priv - privilege
268 * @param[out] authType - enabled authentication type
269 *
270 * @return IPMI_CC_OK for success, others for failure.
271 */
272ipmi_ret_t getChannelEnabledAuthType(const uint8_t& chNum, const uint8_t& priv,
273 EAuthType& authType);
274
275} // namespace ipmi