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/message.hpp> |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 20 | #include <string> |
| 21 | |
| 22 | namespace ipmi |
| 23 | { |
| 24 | |
| 25 | static constexpr uint8_t maxIpmiChannels = 16; |
Richard Marian Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 26 | static constexpr uint8_t currentChNum = 0xE; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 27 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 28 | /** |
| 29 | * @enum IPMI return codes specific to channel (refer spec se 22.22 response |
| 30 | * data) |
| 31 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 32 | enum 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 Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 38 | /** |
| 39 | * @enum Channel Protocol Type (refer spec sec 6.4) |
| 40 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 41 | enum 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 Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 56 | /** |
| 57 | * @enum Channel Medium Type (refer spec sec 6.5) |
| 58 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 59 | enum 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 Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 78 | /** |
| 79 | * @enum Channel Session Type (refer spec sec 22.24 - |
| 80 | * response data byte 5) |
| 81 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 82 | enum class EChannelSessSupported : uint8_t |
| 83 | { |
| 84 | none = 0, |
| 85 | single = 1, |
| 86 | multi = 2, |
| 87 | any = 3, |
| 88 | }; |
| 89 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 90 | /** |
| 91 | * @enum Channel Access Mode (refer spec sec 6.6) |
| 92 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 93 | enum class EChannelAccessMode : uint8_t |
| 94 | { |
| 95 | disabled = 0, |
| 96 | preboot = 1, |
| 97 | alwaysAvail = 2, |
| 98 | shared = 3, |
| 99 | }; |
| 100 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 101 | /** |
| 102 | * @enum Authentication Types (refer spec sec 13.6 - IPMI |
| 103 | * Session Header) |
| 104 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 105 | enum 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 Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 115 | /** |
| 116 | * @enum Access mode for channel access set/get (refer spec |
| 117 | * sec 22.22 - request byte 2[7:6]) |
| 118 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 119 | typedef enum |
| 120 | { |
| 121 | doNotSet = 0x00, |
| 122 | nvData = 0x01, |
| 123 | activeData = 0x02, |
| 124 | reserved = 0x03, |
| 125 | } EChannelActionType; |
| 126 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 127 | /** |
| 128 | * @enum Access set flag to determine changes that has to be updated |
| 129 | * in channel access data configuration. |
| 130 | */ |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 131 | enum 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 Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 140 | /** @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 Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 146 | struct ChannelAccess |
| 147 | { |
| 148 | uint8_t accessMode; |
| 149 | bool userAuthDisabled; |
| 150 | bool perMsgAuthDisabled; |
| 151 | bool alertingDisabled; |
| 152 | uint8_t privLimit; |
| 153 | }; |
| 154 | |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 155 | /** @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 Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 161 | struct 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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 178 | bool isValidChannel(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 179 | |
| 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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 186 | bool doesDeviceExist(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 187 | |
| 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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 194 | bool isValidPrivLimit(const uint8_t privLimit); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 195 | |
| 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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 202 | bool isValidAccessMode(const uint8_t accessMode); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 203 | |
| 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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 211 | bool isValidAuthType(const uint8_t chNum, const EAuthType& authType); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 212 | |
| 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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 219 | EChannelSessSupported getChannelSessionSupport(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 220 | |
| 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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 227 | int getChannelActiveSessions(const uint8_t chNum); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 228 | |
Vernon Mauery | 5831712 | 2018-11-28 11:02:43 -0800 | [diff] [blame] | 229 | /** @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 | */ |
| 235 | size_t getChannelMaxTransferSize(uint8_t chNum); |
| 236 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 237 | /** @brief initializes channel management |
| 238 | * |
| 239 | * @return IPMI_CC_OK for success, others for failure. |
| 240 | */ |
| 241 | ipmi_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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 250 | ipmi_ret_t getChannelInfo(const uint8_t chNum, ChannelInfo& chInfo); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 251 | |
| 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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 259 | ipmi_ret_t getChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 260 | ChannelAccess& chAccessData); |
| 261 | |
Richard Marian Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 262 | /** @brief provides function to convert current channel number (0xE) |
| 263 | * |
| 264 | * @param[in] chNum - channel number as requested in commands. |
Richard Marian Thomaiyar | 30b0112 | 2019-04-03 15:46:03 +0530 | [diff] [blame] | 265 | * @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 | */ |
| 270 | inline 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 Thomaiyar | a39208e | 2018-12-08 17:27:11 +0530 | [diff] [blame] | 283 | * |
| 284 | * @return same channel number or proper channel number for current channel |
| 285 | * number (0xE). |
| 286 | */ |
| 287 | uint8_t convertCurrentChannelNum(const uint8_t chNum); |
| 288 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 289 | /** @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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 297 | ipmi_ret_t setChannelAccessData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 298 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 299 | const uint8_t setFlag); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 300 | |
| 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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 308 | ipmi_ret_t getChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 309 | 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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 319 | ipmi_ret_t setChannelAccessPersistData(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 320 | const ChannelAccess& chAccessData, |
Richard Marian Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 321 | const uint8_t setFlag); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 322 | |
| 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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 330 | ipmi_ret_t getChannelAuthTypeSupported(const uint8_t chNum, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 331 | 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 Thomaiyar | a45cb34 | 2018-12-03 15:08:59 +0530 | [diff] [blame] | 341 | ipmi_ret_t getChannelEnabledAuthType(const uint8_t chNum, const uint8_t priv, |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 342 | EAuthType& authType); |
| 343 | |
Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 344 | /** @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 Thomaiyar | 55768e3 | 2019-03-02 22:54:37 +0530 | [diff] [blame] | 350 | std::string getChannelName(const uint8_t chNum); |
Johnathan Mantey | 74a2102 | 2018-12-13 13:17:56 -0800 | [diff] [blame] | 351 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 352 | } // namespace ipmi |