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