blob: 94570fb873659213205dc385c8f5d28e2aec859c [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
William A. Kennington III194375f2018-12-14 02:14:33 -080017#include <ipmid/api.h>
AppaRao Puli071f3f22018-05-24 16:45:30 +053018
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +053019#include <ipmid/message.hpp>
AppaRao Puli071f3f22018-05-24 16:45:30 +053020#include <string>
21
22namespace ipmi
23{
24
25static constexpr uint8_t maxIpmiChannels = 16;
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +053026static constexpr uint8_t currentChNum = 0xE;
AppaRao Puli071f3f22018-05-24 16:45:30 +053027
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053028/**
29 * @enum IPMI return codes specific to channel (refer spec se 22.22 response
30 * data)
31 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053032enum ipmi_channel_return_codes
33{
34 IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL = 0x82,
35 IPMI_CC_ACCESS_MODE_NOT_SUPPORTED_FOR_CHANEL = 0x83
36};
37
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053038/**
39 * @enum Channel Protocol Type (refer spec sec 6.4)
40 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053041enum class EChannelProtocolType : uint8_t
42{
43 na = 0x00,
44 ipmbV10 = 0x01,
45 icmbV11 = 0x02,
46 reserved = 0x03,
47 ipmiSmbus = 0x04,
48 kcs = 0x05,
49 smic = 0x06,
50 bt10 = 0x07,
51 bt15 = 0x08,
52 tMode = 0x09,
53 oem = 0x1C,
54};
55
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053056/**
57 * @enum Channel Medium Type (refer spec sec 6.5)
58 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053059enum class EChannelMediumType : uint8_t
60{
61 reserved = 0x00,
62 ipmb = 0x01,
63 icmbV10 = 0x02,
64 icmbV09 = 0x03,
65 lan8032 = 0x04,
66 serial = 0x05,
67 otherLan = 0x06,
68 pciSmbus = 0x07,
69 smbusV11 = 0x08,
70 smbusV20 = 0x09,
71 usbV1x = 0x0A,
72 usbV2x = 0x0B,
73 systemInterface = 0x0C,
74 oem = 0x60,
75 unknown = 0x82,
76};
77
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053078/**
79 * @enum Channel Session Type (refer spec sec 22.24 -
80 * response data byte 5)
81 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053082enum class EChannelSessSupported : uint8_t
83{
84 none = 0,
85 single = 1,
86 multi = 2,
87 any = 3,
88};
89
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053090/**
91 * @enum Channel Access Mode (refer spec sec 6.6)
92 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053093enum class EChannelAccessMode : uint8_t
94{
95 disabled = 0,
96 preboot = 1,
97 alwaysAvail = 2,
98 shared = 3,
99};
100
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530101/**
102 * @enum Authentication Types (refer spec sec 13.6 - IPMI
103 * Session Header)
104 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530105enum class EAuthType : uint8_t
106{
107 none = (1 << 0x0),
108 md2 = (1 << 0x1),
109 md5 = (1 << 0x2),
110 reserved = (1 << 0x3),
111 straightPasswd = (1 << 0x4),
112 oem = (1 << 0x5),
113};
114
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530115/**
116 * @enum Access mode for channel access set/get (refer spec
117 * sec 22.22 - request byte 2[7:6])
118 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530119typedef enum
120{
121 doNotSet = 0x00,
122 nvData = 0x01,
123 activeData = 0x02,
124 reserved = 0x03,
125} EChannelActionType;
126
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530127/**
128 * @enum Access set flag to determine changes that has to be updated
129 * in channel access data configuration.
130 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530131enum AccessSetFlag
132{
133 setAccessMode = (1 << 0),
134 setUserAuthEnabled = (1 << 1),
135 setMsgAuthEnabled = (1 << 2),
136 setAlertingEnabled = (1 << 3),
137 setPrivLimit = (1 << 4),
138};
139
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530140/** @struct ChannelAccess
141 *
142 * Structure to store channel access related information, defined in IPMI
143 * specification and used in Get / Set channel access (refer spec sec 22.22
144 * & 22.23)
145 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530146struct ChannelAccess
147{
148 uint8_t accessMode;
149 bool userAuthDisabled;
150 bool perMsgAuthDisabled;
151 bool alertingDisabled;
152 uint8_t privLimit;
153};
154
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530155/** @struct ChannelInfo
156 *
157 * Structure to store data about channel information, which identifies each
158 * channel type and information as defined in IPMI specification. (refer spec
159 * sec 22.22 & 22.23)
160 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530161struct ChannelInfo
162{
163 uint8_t mediumType;
164 uint8_t protocolType;
165 uint8_t sessionSupported;
166 bool isIpmi; // Is session IPMI
167 // This is used in Get LAN Configuration parameter.
168 // This holds the supported AuthTypes for a given channel.
169 uint8_t authTypeSupported;
170};
171
172/** @brief determines valid channel
173 *
174 * @param[in] chNum- channel number
175 *
176 * @return true if valid, false otherwise
177 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530178bool isValidChannel(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530179
180/** @brief determines whether channel device exist
181 *
182 * @param[in] chNum - channel number
183 *
184 * @return true if valid, false otherwise
185 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530186bool doesDeviceExist(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530187
188/** @brief determines whether privilege limit is valid
189 *
190 * @param[in] privLimit - Privilege limit
191 *
192 * @return true if valid, false otherwise
193 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530194bool isValidPrivLimit(const uint8_t privLimit);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530195
196/** @brief determines whether access mode is valid
197 *
198 * @param[in] accessMode - Access mode
199 *
200 * @return true if valid, false otherwise
201 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530202bool isValidAccessMode(const uint8_t accessMode);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530203
204/** @brief determines valid authentication type based on channel number
205 *
206 * @param[in] chNum - channel number
207 * @param[in] authType - authentication type
208 *
209 * @return true if valid, false otherwise
210 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530211bool isValidAuthType(const uint8_t chNum, const EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530212
213/** @brief determines supported session type of a channel
214 *
215 * @param[in] chNum - channel number
216 *
217 * @return EChannelSessSupported - supported session type
218 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530219EChannelSessSupported getChannelSessionSupport(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530220
221/** @brief determines number of active sessions on a channel
222 *
223 * @param[in] chNum - channel number
224 *
225 * @return numer of active sessions
226 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530227int getChannelActiveSessions(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530228
Vernon Mauery58317122018-11-28 11:02:43 -0800229/** @brief determines maximum transfer size for a channel
230 *
231 * @param[in] chNum - channel number
232 *
233 * @return maximum bytes that can be transferred on this channel
234 */
235size_t getChannelMaxTransferSize(uint8_t chNum);
236
AppaRao Puli071f3f22018-05-24 16:45:30 +0530237/** @brief initializes channel management
238 *
239 * @return IPMI_CC_OK for success, others for failure.
240 */
241ipmi_ret_t ipmiChannelInit();
242
243/** @brief provides channel info details
244 *
245 * @param[in] chNum - channel number
246 * @param[out] chInfo - channel info details
247 *
248 * @return IPMI_CC_OK for success, others for failure.
249 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530250ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530251
252/** @brief provides channel access data
253 *
254 * @param[in] chNum - channel number
255 * @param[out] chAccessData -channel access data
256 *
257 * @return IPMI_CC_OK for success, others for failure.
258 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530259ipmi_ret_t getChannelAccessData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530260 ChannelAccess& chAccessData);
261
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +0530262/** @brief provides function to convert current channel number (0xE)
263 *
264 * @param[in] chNum - channel number as requested in commands.
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530265 * @param[in] ipmi::context - ipmi context ptr, which has more details
266 *
267 * @return same channel number or proper channel number for current channel
268 * number (0xE).
269 */
270inline uint8_t convertCurrentChannelNum(const uint8_t chNum,
271 ipmi::Context::ptr ctx)
272{
273 if (chNum == currentChNum)
274 {
275 return ctx->channel;
276 }
277 return chNum;
278}
279
280/** @brief provides function to convert current channel number (0xE)
281 *
282 * @param[in] chNum - channel number as requested in commands.
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +0530283 *
284 * @return same channel number or proper channel number for current channel
285 * number (0xE).
286 */
287uint8_t convertCurrentChannelNum(const uint8_t chNum);
288
AppaRao Puli071f3f22018-05-24 16:45:30 +0530289/** @brief to set channel access data
290 *
291 * @param[in] chNum - channel number
292 * @param[in] chAccessData - channel access data
293 * @param[in] setFlag - flag to indicate updatable fields
294 *
295 * @return IPMI_CC_OK for success, others for failure.
296 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530297ipmi_ret_t setChannelAccessData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530298 const ChannelAccess& chAccessData,
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530299 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530300
301/** @brief to get channel access data persistent data
302 *
303 * @param[in] chNum - channel number
304 * @param[out] chAccessData - channel access data
305 *
306 * @return IPMI_CC_OK for success, others for failure.
307 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530308ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530309 ChannelAccess& chAccessData);
310
311/** @brief to set channel access data persistent data
312 *
313 * @param[in] chNum - channel number
314 * @param[in] chAccessData - channel access data
315 * @param[in] setFlag - flag to indicate updatable fields
316 *
317 * @return IPMI_CC_OK for success, others for failure.
318 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530319ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530320 const ChannelAccess& chAccessData,
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530321 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530322
323/** @brief provides supported authentication type for the channel
324 *
325 * @param[in] chNum - channel number
326 * @param[out] authTypeSupported - supported authentication type
327 *
328 * @return IPMI_CC_OK for success, others for failure.
329 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530330ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530331 uint8_t& authTypeSupported);
332
333/** @brief provides enabled authentication type for the channel
334 *
335 * @param[in] chNum - channel number
336 * @param[in] priv - privilege
337 * @param[out] authType - enabled authentication type
338 *
339 * @return IPMI_CC_OK for success, others for failure.
340 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530341ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530342 EAuthType& authType);
343
Johnathan Mantey74a21022018-12-13 13:17:56 -0800344/** @brief Retrieves the LAN channel name from the IPMI channel number
345 *
346 * @param[in] chNum - IPMI channel number
347 *
348 * @return the LAN channel name (i.e. eth0)
349 */
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530350std::string getChannelName(const uint8_t chNum);
Johnathan Mantey74a21022018-12-13 13:17:56 -0800351
AppaRao Puli071f3f22018-05-24 16:45:30 +0530352} // namespace ipmi