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