blob: 430879453700573292f69809db7fabda2a410833 [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;
Vernon Mauery735ee952019-02-15 13:38:52 -080027static constexpr uint8_t invalidChannel = 0xff;
AppaRao Puli071f3f22018-05-24 16:45:30 +053028
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053029/**
30 * @enum IPMI return codes specific to channel (refer spec se 22.22 response
31 * data)
32 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053033enum ipmi_channel_return_codes
34{
35 IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL = 0x82,
36 IPMI_CC_ACCESS_MODE_NOT_SUPPORTED_FOR_CHANEL = 0x83
37};
38
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053039/**
40 * @enum Channel Protocol Type (refer spec sec 6.4)
41 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053042enum class EChannelProtocolType : uint8_t
43{
44 na = 0x00,
45 ipmbV10 = 0x01,
46 icmbV11 = 0x02,
47 reserved = 0x03,
48 ipmiSmbus = 0x04,
49 kcs = 0x05,
50 smic = 0x06,
51 bt10 = 0x07,
52 bt15 = 0x08,
53 tMode = 0x09,
54 oem = 0x1C,
55};
56
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053057/**
58 * @enum Channel Medium Type (refer spec sec 6.5)
59 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053060enum class EChannelMediumType : uint8_t
61{
62 reserved = 0x00,
63 ipmb = 0x01,
64 icmbV10 = 0x02,
65 icmbV09 = 0x03,
66 lan8032 = 0x04,
67 serial = 0x05,
68 otherLan = 0x06,
69 pciSmbus = 0x07,
70 smbusV11 = 0x08,
71 smbusV20 = 0x09,
72 usbV1x = 0x0A,
73 usbV2x = 0x0B,
74 systemInterface = 0x0C,
75 oem = 0x60,
76 unknown = 0x82,
77};
78
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053079/**
80 * @enum Channel Session Type (refer spec sec 22.24 -
81 * response data byte 5)
82 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053083enum class EChannelSessSupported : uint8_t
84{
85 none = 0,
86 single = 1,
87 multi = 2,
88 any = 3,
89};
90
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053091/**
92 * @enum Channel Access Mode (refer spec sec 6.6)
93 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053094enum class EChannelAccessMode : uint8_t
95{
96 disabled = 0,
97 preboot = 1,
98 alwaysAvail = 2,
99 shared = 3,
100};
101
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530102/**
103 * @enum Authentication Types (refer spec sec 13.6 - IPMI
104 * Session Header)
105 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530106enum class EAuthType : uint8_t
107{
108 none = (1 << 0x0),
109 md2 = (1 << 0x1),
110 md5 = (1 << 0x2),
111 reserved = (1 << 0x3),
112 straightPasswd = (1 << 0x4),
113 oem = (1 << 0x5),
114};
115
Saravanan Palanisamyb5a0f162019-03-04 18:34:44 +0530116// TODO: Remove duplicate 'PayloadType' definition from netipmid's message.hpp
117// to phosphor-ipmi-host/include
118/**
119 * @enum Payload Types (refer spec sec 13.27.3)
120 */
121enum class PayloadType : uint8_t
122{
123 IPMI = 0x00,
124 SOL = 0x01,
125 OPEN_SESSION_REQUEST = 0x10,
126 OPEN_SESSION_RESPONSE = 0x11,
127 RAKP1 = 0x12,
128 RAKP2 = 0x13,
129 RAKP3 = 0x14,
130 RAKP4 = 0x15,
131 INVALID = 0xFF,
132};
133
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530134/**
135 * @enum Access mode for channel access set/get (refer spec
136 * sec 22.22 - request byte 2[7:6])
137 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530138typedef enum
139{
140 doNotSet = 0x00,
141 nvData = 0x01,
142 activeData = 0x02,
143 reserved = 0x03,
144} EChannelActionType;
145
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530146/**
147 * @enum Access set flag to determine changes that has to be updated
148 * in channel access data configuration.
149 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530150enum AccessSetFlag
151{
152 setAccessMode = (1 << 0),
153 setUserAuthEnabled = (1 << 1),
154 setMsgAuthEnabled = (1 << 2),
155 setAlertingEnabled = (1 << 3),
156 setPrivLimit = (1 << 4),
157};
158
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530159/** @struct ChannelAccess
160 *
161 * Structure to store channel access related information, defined in IPMI
162 * specification and used in Get / Set channel access (refer spec sec 22.22
163 * & 22.23)
164 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530165struct ChannelAccess
166{
167 uint8_t accessMode;
168 bool userAuthDisabled;
169 bool perMsgAuthDisabled;
170 bool alertingDisabled;
171 uint8_t privLimit;
172};
173
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530174/** @struct ChannelInfo
175 *
176 * Structure to store data about channel information, which identifies each
177 * channel type and information as defined in IPMI specification. (refer spec
178 * sec 22.22 & 22.23)
179 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530180struct ChannelInfo
181{
182 uint8_t mediumType;
183 uint8_t protocolType;
184 uint8_t sessionSupported;
185 bool isIpmi; // Is session IPMI
186 // This is used in Get LAN Configuration parameter.
187 // This holds the supported AuthTypes for a given channel.
188 uint8_t authTypeSupported;
189};
190
191/** @brief determines valid channel
192 *
193 * @param[in] chNum- channel number
194 *
195 * @return true if valid, false otherwise
196 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530197bool isValidChannel(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530198
199/** @brief determines whether channel device exist
200 *
201 * @param[in] chNum - channel number
202 *
203 * @return true if valid, false otherwise
204 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530205bool doesDeviceExist(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530206
207/** @brief determines whether privilege limit is valid
208 *
209 * @param[in] privLimit - Privilege limit
210 *
211 * @return true if valid, false otherwise
212 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530213bool isValidPrivLimit(const uint8_t privLimit);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530214
215/** @brief determines whether access mode is valid
216 *
217 * @param[in] accessMode - Access mode
218 *
219 * @return true if valid, false otherwise
220 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530221bool isValidAccessMode(const uint8_t accessMode);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530222
223/** @brief determines valid authentication type based on channel number
224 *
225 * @param[in] chNum - channel number
226 * @param[in] authType - authentication type
227 *
228 * @return true if valid, false otherwise
229 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530230bool isValidAuthType(const uint8_t chNum, const EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530231
232/** @brief determines supported session type of a channel
233 *
234 * @param[in] chNum - channel number
235 *
236 * @return EChannelSessSupported - supported session type
237 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530238EChannelSessSupported getChannelSessionSupport(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530239
240/** @brief determines number of active sessions on a channel
241 *
242 * @param[in] chNum - channel number
243 *
244 * @return numer of active sessions
245 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530246int getChannelActiveSessions(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530247
Vernon Mauery58317122018-11-28 11:02:43 -0800248/** @brief determines maximum transfer size for a channel
249 *
250 * @param[in] chNum - channel number
251 *
252 * @return maximum bytes that can be transferred on this channel
253 */
254size_t getChannelMaxTransferSize(uint8_t chNum);
255
AppaRao Puli071f3f22018-05-24 16:45:30 +0530256/** @brief initializes channel management
257 *
258 * @return IPMI_CC_OK for success, others for failure.
259 */
260ipmi_ret_t ipmiChannelInit();
261
262/** @brief provides channel info details
263 *
264 * @param[in] chNum - channel number
265 * @param[out] chInfo - channel info details
266 *
267 * @return IPMI_CC_OK for success, others for failure.
268 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530269ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530270
271/** @brief provides channel access data
272 *
273 * @param[in] chNum - channel number
274 * @param[out] chAccessData -channel access data
275 *
276 * @return IPMI_CC_OK for success, others for failure.
277 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530278ipmi_ret_t getChannelAccessData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530279 ChannelAccess& chAccessData);
280
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +0530281/** @brief provides function to convert current channel number (0xE)
282 *
283 * @param[in] chNum - channel number as requested in commands.
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530284 * @param[in] ipmi::context - ipmi context ptr, which has more details
285 *
286 * @return same channel number or proper channel number for current channel
287 * number (0xE).
288 */
289inline uint8_t convertCurrentChannelNum(const uint8_t chNum,
290 ipmi::Context::ptr ctx)
291{
292 if (chNum == currentChNum)
293 {
294 return ctx->channel;
295 }
296 return chNum;
297}
298
299/** @brief provides function to convert current channel number (0xE)
300 *
301 * @param[in] chNum - channel number as requested in commands.
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +0530302 *
303 * @return same channel number or proper channel number for current channel
304 * number (0xE).
305 */
306uint8_t convertCurrentChannelNum(const uint8_t chNum);
307
AppaRao Puli071f3f22018-05-24 16:45:30 +0530308/** @brief to set channel access data
309 *
310 * @param[in] chNum - channel number
311 * @param[in] chAccessData - channel access data
312 * @param[in] setFlag - flag to indicate updatable fields
313 *
314 * @return IPMI_CC_OK for success, others for failure.
315 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530316ipmi_ret_t setChannelAccessData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530317 const ChannelAccess& chAccessData,
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530318 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530319
320/** @brief to get channel access data persistent data
321 *
322 * @param[in] chNum - channel number
323 * @param[out] chAccessData - channel access data
324 *
325 * @return IPMI_CC_OK for success, others for failure.
326 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530327ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530328 ChannelAccess& chAccessData);
329
330/** @brief to set channel access data persistent data
331 *
332 * @param[in] chNum - channel number
333 * @param[in] chAccessData - channel access data
334 * @param[in] setFlag - flag to indicate updatable fields
335 *
336 * @return IPMI_CC_OK for success, others for failure.
337 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530338ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530339 const ChannelAccess& chAccessData,
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530340 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530341
342/** @brief provides supported authentication type for the channel
343 *
344 * @param[in] chNum - channel number
345 * @param[out] authTypeSupported - supported authentication type
346 *
347 * @return IPMI_CC_OK for success, others for failure.
348 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530349ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530350 uint8_t& authTypeSupported);
351
352/** @brief provides enabled authentication type for the channel
353 *
354 * @param[in] chNum - channel number
355 * @param[in] priv - privilege
356 * @param[out] authType - enabled authentication type
357 *
358 * @return IPMI_CC_OK for success, others for failure.
359 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530360ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
AppaRao Puli071f3f22018-05-24 16:45:30 +0530361 EAuthType& authType);
362
Johnathan Mantey74a21022018-12-13 13:17:56 -0800363/** @brief Retrieves the LAN channel name from the IPMI channel number
364 *
365 * @param[in] chNum - IPMI channel number
366 *
367 * @return the LAN channel name (i.e. eth0)
368 */
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530369std::string getChannelName(const uint8_t chNum);
Johnathan Mantey74a21022018-12-13 13:17:56 -0800370
Vernon Mauery735ee952019-02-15 13:38:52 -0800371/** @brief Retrieves the LAN channel number from the IPMI channel name
372 *
373 * @param[in] chName - IPMI channel name (i.e. eth0)
374 *
375 * @return the LAN channel number
376 */
377uint8_t getChannelByName(const std::string& chName);
378
AppaRao Puli071f3f22018-05-24 16:45:30 +0530379} // namespace ipmi