AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 1 | /* |
| 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 III | 194375f | 2018-12-14 02:14:33 -0800 | [diff] [blame] | 17 | #include <ipmid/api.h> |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 18 | |
Richard Marian Thomaiyar | 30b0112 | 2019-04-03 15:46:03 +0530 | [diff] [blame^] | 19 | #include <ipmid/api.hpp> |
| 20 | #include <ipmid/message.hpp> |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 21 | #include <string> |
| 22 | |
| 23 | namespace ipmi |
| 24 | { |
| 25 | |
| 26 | static constexpr uint8_t maxIpmiChannels = 16; |
Richard Marian Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 27 | static constexpr uint8_t currentChNum = 0xE; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 28 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 29 | /** |
| 30 | * @enum IPMI return codes specific to channel (refer spec se 22.22 response |
| 31 | * data) |
| 32 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 33 | enum 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 Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 39 | /** |
| 40 | * @enum Channel Protocol Type (refer spec sec 6.4) |
| 41 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 42 | enum 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 Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 57 | /** |
| 58 | * @enum Channel Medium Type (refer spec sec 6.5) |
| 59 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 60 | enum 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 Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 79 | /** |
| 80 | * @enum Channel Session Type (refer spec sec 22.24 - |
| 81 | * response data byte 5) |
| 82 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 83 | enum class EChannelSessSupported : uint8_t |
| 84 | { |
| 85 | none = 0, |
| 86 | single = 1, |
| 87 | multi = 2, |
| 88 | any = 3, |
| 89 | }; |
| 90 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 91 | /** |
| 92 | * @enum Channel Access Mode (refer spec sec 6.6) |
| 93 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 94 | enum class EChannelAccessMode : uint8_t |
| 95 | { |
| 96 | disabled = 0, |
| 97 | preboot = 1, |
| 98 | alwaysAvail = 2, |
| 99 | shared = 3, |
| 100 | }; |
| 101 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 102 | /** |
| 103 | * @enum Authentication Types (refer spec sec 13.6 - IPMI |
| 104 | * Session Header) |
| 105 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 106 | enum 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 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 116 | /** |
| 117 | * @enum Access mode for channel access set/get (refer spec |
| 118 | * sec 22.22 - request byte 2[7:6]) |
| 119 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 120 | typedef enum |
| 121 | { |
| 122 | doNotSet = 0x00, |
| 123 | nvData = 0x01, |
| 124 | activeData = 0x02, |
| 125 | reserved = 0x03, |
| 126 | } EChannelActionType; |
| 127 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 128 | /** |
| 129 | * @enum Access set flag to determine changes that has to be updated |
| 130 | * in channel access data configuration. |
| 131 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 132 | enum AccessSetFlag |
| 133 | { |
| 134 | setAccessMode = (1 << 0), |
| 135 | setUserAuthEnabled = (1 << 1), |
| 136 | setMsgAuthEnabled = (1 << 2), |
| 137 | setAlertingEnabled = (1 << 3), |
| 138 | setPrivLimit = (1 << 4), |
| 139 | }; |
| 140 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 141 | /** @struct ChannelAccess |
| 142 | * |
| 143 | * Structure to store channel access related information, defined in IPMI |
| 144 | * specification and used in Get / Set channel access (refer spec sec 22.22 |
| 145 | * & 22.23) |
| 146 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 147 | struct ChannelAccess |
| 148 | { |
| 149 | uint8_t accessMode; |
| 150 | bool userAuthDisabled; |
| 151 | bool perMsgAuthDisabled; |
| 152 | bool alertingDisabled; |
| 153 | uint8_t privLimit; |
| 154 | }; |
| 155 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 156 | /** @struct ChannelInfo |
| 157 | * |
| 158 | * Structure to store data about channel information, which identifies each |
| 159 | * channel type and information as defined in IPMI specification. (refer spec |
| 160 | * sec 22.22 & 22.23) |
| 161 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 162 | struct ChannelInfo |
| 163 | { |
| 164 | uint8_t mediumType; |
| 165 | uint8_t protocolType; |
| 166 | uint8_t sessionSupported; |
| 167 | bool isIpmi; // Is session IPMI |
| 168 | // This is used in Get LAN Configuration parameter. |
| 169 | // This holds the supported AuthTypes for a given channel. |
| 170 | uint8_t authTypeSupported; |
| 171 | }; |
| 172 | |
| 173 | /** @brief determines valid channel |
| 174 | * |
| 175 | * @param[in] chNum- channel number |
| 176 | * |
| 177 | * @return true if valid, false otherwise |
| 178 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 179 | bool isValidChannel(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 180 | |
| 181 | /** @brief determines whether channel device exist |
| 182 | * |
| 183 | * @param[in] chNum - channel number |
| 184 | * |
| 185 | * @return true if valid, false otherwise |
| 186 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 187 | bool doesDeviceExist(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 188 | |
| 189 | /** @brief determines whether privilege limit is valid |
| 190 | * |
| 191 | * @param[in] privLimit - Privilege limit |
| 192 | * |
| 193 | * @return true if valid, false otherwise |
| 194 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 195 | bool isValidPrivLimit(const uint8_t privLimit); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 196 | |
| 197 | /** @brief determines whether access mode is valid |
| 198 | * |
| 199 | * @param[in] accessMode - Access mode |
| 200 | * |
| 201 | * @return true if valid, false otherwise |
| 202 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 203 | bool isValidAccessMode(const uint8_t accessMode); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 204 | |
| 205 | /** @brief determines valid authentication type based on channel number |
| 206 | * |
| 207 | * @param[in] chNum - channel number |
| 208 | * @param[in] authType - authentication type |
| 209 | * |
| 210 | * @return true if valid, false otherwise |
| 211 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 212 | bool isValidAuthType(const uint8_t chNum, const EAuthType& authType); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 213 | |
| 214 | /** @brief determines supported session type of a channel |
| 215 | * |
| 216 | * @param[in] chNum - channel number |
| 217 | * |
| 218 | * @return EChannelSessSupported - supported session type |
| 219 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 220 | EChannelSessSupported getChannelSessionSupport(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 221 | |
| 222 | /** @brief determines number of active sessions on a channel |
| 223 | * |
| 224 | * @param[in] chNum - channel number |
| 225 | * |
| 226 | * @return numer of active sessions |
| 227 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 228 | int getChannelActiveSessions(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 229 | |
Vernon Mauery | 5831712 | 2018-11-28 11:02:43 -0800 | [diff] [blame] | 230 | /** @brief determines maximum transfer size for a channel |
| 231 | * |
| 232 | * @param[in] chNum - channel number |
| 233 | * |
| 234 | * @return maximum bytes that can be transferred on this channel |
| 235 | */ |
| 236 | size_t getChannelMaxTransferSize(uint8_t chNum); |
| 237 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 238 | /** @brief initializes channel management |
| 239 | * |
| 240 | * @return IPMI_CC_OK for success, others for failure. |
| 241 | */ |
| 242 | ipmi_ret_t ipmiChannelInit(); |
| 243 | |
| 244 | /** @brief provides channel info details |
| 245 | * |
| 246 | * @param[in] chNum - channel number |
| 247 | * @param[out] chInfo - channel info details |
| 248 | * |
| 249 | * @return IPMI_CC_OK for success, others for failure. |
| 250 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 251 | ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 252 | |
| 253 | /** @brief provides channel access data |
| 254 | * |
| 255 | * @param[in] chNum - channel number |
| 256 | * @param[out] chAccessData -channel access data |
| 257 | * |
| 258 | * @return IPMI_CC_OK for success, others for failure. |
| 259 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 260 | ipmi_ret_t getChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 261 | ChannelAccess& chAccessData); |
| 262 | |
Richard Marian Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 263 | /** @brief provides function to convert current channel number (0xE) |
| 264 | * |
| 265 | * @param[in] chNum - channel number as requested in commands. |
Richard Marian Thomaiyar | 30b0112 | 2019-04-03 15:46:03 +0530 | [diff] [blame^] | 266 | * @param[in] ipmi::context - ipmi context ptr, which has more details |
| 267 | * |
| 268 | * @return same channel number or proper channel number for current channel |
| 269 | * number (0xE). |
| 270 | */ |
| 271 | inline uint8_t convertCurrentChannelNum(const uint8_t chNum, |
| 272 | ipmi::Context::ptr ctx) |
| 273 | { |
| 274 | if (chNum == currentChNum) |
| 275 | { |
| 276 | return ctx->channel; |
| 277 | } |
| 278 | return chNum; |
| 279 | } |
| 280 | |
| 281 | /** @brief provides function to convert current channel number (0xE) |
| 282 | * |
| 283 | * @param[in] chNum - channel number as requested in commands. |
Richard Marian Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 284 | * |
| 285 | * @return same channel number or proper channel number for current channel |
| 286 | * number (0xE). |
| 287 | */ |
| 288 | uint8_t convertCurrentChannelNum(const uint8_t chNum); |
| 289 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 290 | /** @brief to set channel access data |
| 291 | * |
| 292 | * @param[in] chNum - channel number |
| 293 | * @param[in] chAccessData - channel access data |
| 294 | * @param[in] setFlag - flag to indicate updatable fields |
| 295 | * |
| 296 | * @return IPMI_CC_OK for success, others for failure. |
| 297 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 298 | ipmi_ret_t setChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 299 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 300 | const uint8_t setFlag); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 301 | |
| 302 | /** @brief to get channel access data persistent data |
| 303 | * |
| 304 | * @param[in] chNum - channel number |
| 305 | * @param[out] chAccessData - channel access data |
| 306 | * |
| 307 | * @return IPMI_CC_OK for success, others for failure. |
| 308 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 309 | ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 310 | ChannelAccess& chAccessData); |
| 311 | |
| 312 | /** @brief to set channel access data persistent data |
| 313 | * |
| 314 | * @param[in] chNum - channel number |
| 315 | * @param[in] chAccessData - channel access data |
| 316 | * @param[in] setFlag - flag to indicate updatable fields |
| 317 | * |
| 318 | * @return IPMI_CC_OK for success, others for failure. |
| 319 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 320 | ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 321 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 322 | const uint8_t setFlag); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 323 | |
| 324 | /** @brief provides supported authentication type for the channel |
| 325 | * |
| 326 | * @param[in] chNum - channel number |
| 327 | * @param[out] authTypeSupported - supported authentication type |
| 328 | * |
| 329 | * @return IPMI_CC_OK for success, others for failure. |
| 330 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 331 | ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 332 | uint8_t& authTypeSupported); |
| 333 | |
| 334 | /** @brief provides enabled authentication type for the channel |
| 335 | * |
| 336 | * @param[in] chNum - channel number |
| 337 | * @param[in] priv - privilege |
| 338 | * @param[out] authType - enabled authentication type |
| 339 | * |
| 340 | * @return IPMI_CC_OK for success, others for failure. |
| 341 | */ |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 342 | ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 343 | EAuthType& authType); |
| 344 | |
Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 345 | /** @brief Retrieves the LAN channel name from the IPMI channel number |
| 346 | * |
| 347 | * @param[in] chNum - IPMI channel number |
| 348 | * |
| 349 | * @return the LAN channel name (i.e. eth0) |
| 350 | */ |
Richard Marian Thomaiyar | 55768e3 | 2019-03-02 22:54:37 +0530 | [diff] [blame] | 351 | std::string getChannelName(const uint8_t chNum); |
Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 352 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 353 | } // namespace ipmi |