blob: 0fefe2e4e12769d0be9be74a9a919239cd1990d1 [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
Sumanth Bhate4e633e2019-05-14 12:13:57 +000017#include <array>
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000018#include <ipmid/api.hpp>
AppaRao Puli071f3f22018-05-24 16:45:30 +053019#include <string>
20
21namespace ipmi
22{
23
24static constexpr uint8_t maxIpmiChannels = 16;
Richard Marian Thomaiyara39208e2018-12-08 17:27:11 +053025static constexpr uint8_t currentChNum = 0xE;
Vernon Mauery735ee952019-02-15 13:38:52 -080026static constexpr uint8_t invalidChannel = 0xff;
AppaRao Puli071f3f22018-05-24 16:45:30 +053027
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053028/**
Sumanth Bhate4e633e2019-05-14 12:13:57 +000029 * @array of privilege levels
30 */
31extern const std::array<std::string, PRIVILEGE_OEM + 1> privList;
32
33/**
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053034 * @enum IPMI return codes specific to channel (refer spec se 22.22 response
35 * data)
36 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +000037constexpr Cc ccActionNotSupportedForChannel = 0x82;
38constexpr Cc ccAccessModeNotSupportedForChannel = 0x83;
AppaRao Puli071f3f22018-05-24 16:45:30 +053039
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053040/**
41 * @enum Channel Protocol Type (refer spec sec 6.4)
42 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053043enum class EChannelProtocolType : uint8_t
44{
45 na = 0x00,
46 ipmbV10 = 0x01,
47 icmbV11 = 0x02,
48 reserved = 0x03,
49 ipmiSmbus = 0x04,
50 kcs = 0x05,
51 smic = 0x06,
52 bt10 = 0x07,
53 bt15 = 0x08,
54 tMode = 0x09,
55 oem = 0x1C,
56};
57
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053058/**
59 * @enum Channel Medium Type (refer spec sec 6.5)
60 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053061enum class EChannelMediumType : uint8_t
62{
63 reserved = 0x00,
64 ipmb = 0x01,
65 icmbV10 = 0x02,
66 icmbV09 = 0x03,
67 lan8032 = 0x04,
68 serial = 0x05,
69 otherLan = 0x06,
70 pciSmbus = 0x07,
71 smbusV11 = 0x08,
72 smbusV20 = 0x09,
73 usbV1x = 0x0A,
74 usbV2x = 0x0B,
75 systemInterface = 0x0C,
76 oem = 0x60,
77 unknown = 0x82,
78};
79
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053080/**
81 * @enum Channel Session Type (refer spec sec 22.24 -
82 * response data byte 5)
83 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053084enum class EChannelSessSupported : uint8_t
85{
86 none = 0,
87 single = 1,
88 multi = 2,
89 any = 3,
90};
91
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +053092/**
93 * @enum Channel Access Mode (refer spec sec 6.6)
94 */
AppaRao Puli071f3f22018-05-24 16:45:30 +053095enum class EChannelAccessMode : uint8_t
96{
97 disabled = 0,
98 preboot = 1,
99 alwaysAvail = 2,
100 shared = 3,
101};
102
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530103/**
104 * @enum Authentication Types (refer spec sec 13.6 - IPMI
105 * Session Header)
106 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530107enum class EAuthType : uint8_t
108{
109 none = (1 << 0x0),
110 md2 = (1 << 0x1),
111 md5 = (1 << 0x2),
112 reserved = (1 << 0x3),
113 straightPasswd = (1 << 0x4),
114 oem = (1 << 0x5),
115};
116
Saravanan Palanisamyb5a0f162019-03-04 18:34:44 +0530117// TODO: Remove duplicate 'PayloadType' definition from netipmid's message.hpp
118// to phosphor-ipmi-host/include
119/**
120 * @enum Payload Types (refer spec sec 13.27.3)
121 */
122enum class PayloadType : uint8_t
123{
124 IPMI = 0x00,
125 SOL = 0x01,
126 OPEN_SESSION_REQUEST = 0x10,
127 OPEN_SESSION_RESPONSE = 0x11,
128 RAKP1 = 0x12,
129 RAKP2 = 0x13,
130 RAKP3 = 0x14,
131 RAKP4 = 0x15,
132 INVALID = 0xFF,
133};
134
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530135/**
136 * @enum Access mode for channel access set/get (refer spec
137 * sec 22.22 - request byte 2[7:6])
138 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530139typedef enum
140{
141 doNotSet = 0x00,
142 nvData = 0x01,
143 activeData = 0x02,
144 reserved = 0x03,
145} EChannelActionType;
146
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530147/**
148 * @enum Access set flag to determine changes that has to be updated
149 * in channel access data configuration.
150 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530151enum AccessSetFlag
152{
153 setAccessMode = (1 << 0),
154 setUserAuthEnabled = (1 << 1),
155 setMsgAuthEnabled = (1 << 2),
156 setAlertingEnabled = (1 << 3),
157 setPrivLimit = (1 << 4),
158};
159
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530160/** @struct ChannelAccess
161 *
162 * Structure to store channel access related information, defined in IPMI
163 * specification and used in Get / Set channel access (refer spec sec 22.22
164 * & 22.23)
165 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530166struct ChannelAccess
167{
168 uint8_t accessMode;
169 bool userAuthDisabled;
170 bool perMsgAuthDisabled;
171 bool alertingDisabled;
172 uint8_t privLimit;
173};
174
Richard Marian Thomaiyar6e1ba9e2018-11-29 06:29:21 +0530175/** @struct ChannelInfo
176 *
177 * Structure to store data about channel information, which identifies each
178 * channel type and information as defined in IPMI specification. (refer spec
179 * sec 22.22 & 22.23)
180 */
AppaRao Puli071f3f22018-05-24 16:45:30 +0530181struct ChannelInfo
182{
183 uint8_t mediumType;
184 uint8_t protocolType;
185 uint8_t sessionSupported;
186 bool isIpmi; // Is session IPMI
187 // This is used in Get LAN Configuration parameter.
188 // This holds the supported AuthTypes for a given channel.
189 uint8_t authTypeSupported;
190};
191
192/** @brief determines valid channel
193 *
194 * @param[in] chNum- channel number
195 *
196 * @return true if valid, false otherwise
197 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530198bool isValidChannel(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530199
200/** @brief determines whether channel device exist
201 *
202 * @param[in] chNum - channel number
203 *
204 * @return true if valid, false otherwise
205 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530206bool doesDeviceExist(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530207
208/** @brief determines whether privilege limit is valid
209 *
210 * @param[in] privLimit - Privilege limit
211 *
212 * @return true if valid, false otherwise
213 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530214bool isValidPrivLimit(const uint8_t privLimit);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530215
216/** @brief determines whether access mode is valid
217 *
218 * @param[in] accessMode - Access mode
219 *
220 * @return true if valid, false otherwise
221 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530222bool isValidAccessMode(const uint8_t accessMode);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530223
224/** @brief determines valid authentication type based on channel number
225 *
226 * @param[in] chNum - channel number
227 * @param[in] authType - authentication type
228 *
229 * @return true if valid, false otherwise
230 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530231bool isValidAuthType(const uint8_t chNum, const EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530232
233/** @brief determines supported session type of a channel
234 *
235 * @param[in] chNum - channel number
236 *
237 * @return EChannelSessSupported - supported session type
238 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530239EChannelSessSupported getChannelSessionSupport(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530240
241/** @brief determines number of active sessions on a channel
242 *
243 * @param[in] chNum - channel number
244 *
245 * @return numer of active sessions
246 */
Richard Marian Thomaiyara45cb342018-12-03 15:08:59 +0530247int getChannelActiveSessions(const uint8_t chNum);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530248
Vernon Mauery58317122018-11-28 11:02:43 -0800249/** @brief determines maximum transfer size for a channel
250 *
251 * @param[in] chNum - channel number
252 *
253 * @return maximum bytes that can be transferred on this channel
254 */
255size_t getChannelMaxTransferSize(uint8_t chNum);
256
AppaRao Puli071f3f22018-05-24 16:45:30 +0530257/** @brief initializes channel management
258 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000259 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530260 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000261Cc ipmiChannelInit();
AppaRao Puli071f3f22018-05-24 16:45:30 +0530262
263/** @brief provides channel info details
264 *
265 * @param[in] chNum - channel number
266 * @param[out] chInfo - channel info details
267 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000268 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530269 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000270Cc getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530271
272/** @brief provides channel access data
273 *
274 * @param[in] chNum - channel number
275 * @param[out] chAccessData -channel access data
276 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000277 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530278 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000279Cc getChannelAccessData(const uint8_t chNum, ChannelAccess& chAccessData);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530280
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.
Vernon Mauery5ed39592019-05-14 09:16:53 -0700284 * @param[in] devChannel - channel number as provided by device (not 0xE)
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530285 *
286 * @return same channel number or proper channel number for current channel
287 * number (0xE).
288 */
Vernon Mauery5ed39592019-05-14 09:16:53 -0700289static inline uint8_t convertCurrentChannelNum(const uint8_t chNum,
290 const uint8_t devChannel)
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530291{
292 if (chNum == currentChNum)
293 {
Vernon Mauery5ed39592019-05-14 09:16:53 -0700294 return devChannel;
Richard Marian Thomaiyar30b01122019-04-03 15:46:03 +0530295 }
296 return chNum;
297}
298
AppaRao Puli071f3f22018-05-24 16:45:30 +0530299/** @brief to set channel access data
300 *
301 * @param[in] chNum - channel number
302 * @param[in] chAccessData - channel access data
303 * @param[in] setFlag - flag to indicate updatable fields
304 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000305 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530306 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000307Cc setChannelAccessData(const uint8_t chNum, const ChannelAccess& chAccessData,
308 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530309
310/** @brief to get channel access data persistent data
311 *
312 * @param[in] chNum - channel number
313 * @param[out] chAccessData - channel access data
314 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000315 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530316 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000317Cc getChannelAccessPersistData(const uint8_t chNum,
318 ChannelAccess& chAccessData);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530319
320/** @brief to set channel access data persistent data
321 *
322 * @param[in] chNum - channel number
323 * @param[in] chAccessData - channel access data
324 * @param[in] setFlag - flag to indicate updatable fields
325 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000326 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530327 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000328Cc setChannelAccessPersistData(const uint8_t chNum,
329 const ChannelAccess& chAccessData,
330 const uint8_t setFlag);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530331
332/** @brief provides supported authentication type for the channel
333 *
334 * @param[in] chNum - channel number
335 * @param[out] authTypeSupported - supported authentication type
336 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000337 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530338 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000339Cc getChannelAuthTypeSupported(const uint8_t chNum, uint8_t& authTypeSupported);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530340
341/** @brief provides enabled authentication type for the channel
342 *
343 * @param[in] chNum - channel number
344 * @param[in] priv - privilege
345 * @param[out] authType - enabled authentication type
346 *
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000347 * @return ccSuccess for success, others for failure.
AppaRao Puli071f3f22018-05-24 16:45:30 +0530348 */
NITIN SHARMAb541a5a2019-07-18 12:46:59 +0000349Cc getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv,
350 EAuthType& authType);
AppaRao Puli071f3f22018-05-24 16:45:30 +0530351
Johnathan Mantey74a21022018-12-13 13:17:56 -0800352/** @brief Retrieves the LAN channel name from the IPMI channel number
353 *
354 * @param[in] chNum - IPMI channel number
355 *
356 * @return the LAN channel name (i.e. eth0)
357 */
Richard Marian Thomaiyar55768e32019-03-02 22:54:37 +0530358std::string getChannelName(const uint8_t chNum);
Johnathan Mantey74a21022018-12-13 13:17:56 -0800359
Vernon Mauery735ee952019-02-15 13:38:52 -0800360/** @brief Retrieves the LAN channel number from the IPMI channel name
361 *
362 * @param[in] chName - IPMI channel name (i.e. eth0)
363 *
364 * @return the LAN channel number
365 */
366uint8_t getChannelByName(const std::string& chName);
367
Ayushi Smriti6fd812d2019-04-12 18:51:31 +0000368/** @brief determines whether payload type is valid
369 *
370 * @param[in] payload type - Payload Type
371 *
372 * @return true if valid, false otherwise
373 */
374bool isValidPayloadType(const PayloadType payloadType);
375
AppaRao Puli071f3f22018-05-24 16:45:30 +0530376} // namespace ipmi