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