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 | |
| 17 | #include "channelcommands.hpp" |
| 18 | |
| 19 | #include "apphandler.hpp" |
| 20 | #include "channel_layer.hpp" |
| 21 | |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 22 | #include <ipmid/api.hpp> |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 23 | #include <phosphor-logging/log.hpp> |
| 24 | #include <regex> |
| 25 | |
| 26 | using namespace phosphor::logging; |
| 27 | |
| 28 | namespace ipmi |
| 29 | { |
| 30 | |
Richard Marian Thomaiyar | 48e5558 | 2018-12-20 15:58:04 +0530 | [diff] [blame] | 31 | /** @struct GetChannelAccessReq |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 32 | * |
| 33 | * Structure for get channel access request command (refer spec sec 22.23) |
| 34 | */ |
Richard Marian Thomaiyar | 48e5558 | 2018-12-20 15:58:04 +0530 | [diff] [blame] | 35 | struct GetChannelAccessReq |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 36 | { |
| 37 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 38 | uint8_t chNum : 4; |
| 39 | uint8_t reserved_1 : 4; |
| 40 | uint8_t reserved_2 : 6; |
| 41 | uint8_t accessSetMode : 2; |
| 42 | #endif |
| 43 | #if BYTE_ORDER == BIG_ENDIAN |
| 44 | uint8_t reserved_1 : 4; |
| 45 | uint8_t chNum : 4; |
| 46 | uint8_t accessSetMode : 2; |
| 47 | uint8_t reserved_2 : 6; |
| 48 | #endif |
| 49 | } __attribute__((packed)); |
| 50 | |
Richard Marian Thomaiyar | 48e5558 | 2018-12-20 15:58:04 +0530 | [diff] [blame] | 51 | /** @struct GetChannelAccessResp |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 52 | * |
| 53 | * Structure for get channel access response command (refer spec sec 22.23) |
| 54 | */ |
Richard Marian Thomaiyar | 48e5558 | 2018-12-20 15:58:04 +0530 | [diff] [blame] | 55 | struct GetChannelAccessResp |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 56 | { |
| 57 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 58 | uint8_t accessMode : 3; |
| 59 | uint8_t usrAuthDisabled : 1; |
| 60 | uint8_t msgAuthDisabled : 1; |
| 61 | uint8_t alertDisabled : 1; |
| 62 | uint8_t reserved_1 : 2; |
| 63 | uint8_t privLimit : 4; |
| 64 | uint8_t reserved_2 : 4; |
| 65 | #endif |
| 66 | #if BYTE_ORDER == BIG_ENDIAN |
| 67 | uint8_t reserved_1 : 2; |
| 68 | uint8_t alertDisabled : 1; |
| 69 | uint8_t msgAuthDisabled : 1; |
| 70 | uint8_t usrAuthDisabled : 1; |
| 71 | uint8_t accessMode : 3; |
| 72 | uint8_t reserved_2 : 4; |
| 73 | uint8_t privLimit : 4; |
| 74 | #endif |
| 75 | } __attribute__((packed)); |
| 76 | |
Richard Marian Thomaiyar | 48e5558 | 2018-12-20 15:58:04 +0530 | [diff] [blame] | 77 | /** @struct GetChannelInfoReq |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 78 | * |
| 79 | * Structure for get channel info request command (refer spec sec 22.24) |
| 80 | */ |
Richard Marian Thomaiyar | 48e5558 | 2018-12-20 15:58:04 +0530 | [diff] [blame] | 81 | struct GetChannelInfoReq |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 82 | { |
| 83 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 84 | uint8_t chNum : 4; |
| 85 | uint8_t reserved_1 : 4; |
| 86 | #endif |
| 87 | #if BYTE_ORDER == BIG_ENDIAN |
| 88 | uint8_t reserved_1 : 4; |
| 89 | uint8_t chNum : 4; |
| 90 | #endif |
| 91 | } __attribute__((packed)); |
| 92 | |
Richard Marian Thomaiyar | 48e5558 | 2018-12-20 15:58:04 +0530 | [diff] [blame] | 93 | /** @struct GetChannelInfoResp |
Richard Marian Thomaiyar | 6e1ba9e | 2018-11-29 06:29:21 +0530 | [diff] [blame] | 94 | * |
| 95 | * Structure for get channel info response command (refer spec sec 22.24) |
| 96 | */ |
Richard Marian Thomaiyar | 48e5558 | 2018-12-20 15:58:04 +0530 | [diff] [blame] | 97 | struct GetChannelInfoResp |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 98 | { |
| 99 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 100 | uint8_t chNum : 4; |
| 101 | uint8_t reserved_1 : 4; |
| 102 | uint8_t mediumType : 7; |
| 103 | uint8_t reserved_2 : 1; |
| 104 | uint8_t msgProtType : 5; |
| 105 | uint8_t reserved_3 : 3; |
| 106 | uint8_t actSessCount : 6; |
| 107 | uint8_t sessType : 2; |
| 108 | #endif |
| 109 | #if BYTE_ORDER == BIG_ENDIAN |
| 110 | uint8_t reserved_1 : 4; |
| 111 | uint8_t chNum : 4; |
| 112 | uint8_t reserved_2 : 1; |
| 113 | uint8_t mediumType : 7; |
| 114 | uint8_t reserved_3 : 3; |
| 115 | uint8_t msgProtType : 5; |
| 116 | uint8_t sessType : 2; |
| 117 | uint8_t actSessCount : 6; |
| 118 | #endif |
| 119 | uint8_t vendorId[3]; |
| 120 | uint8_t auxChInfo[2]; |
| 121 | } __attribute__((packed)); |
| 122 | |
Saravanan Palanisamy | b5a0f16 | 2019-03-04 18:34:44 +0530 | [diff] [blame] | 123 | /** @struct GetChannelPayloadSupportReq |
| 124 | * |
| 125 | * Structure for get channel payload support command request (refer spec |
| 126 | * sec 24.8) |
| 127 | */ |
| 128 | struct GetChannelPayloadSupportReq |
| 129 | { |
| 130 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 131 | uint8_t chNum : 4; |
| 132 | uint8_t reserved : 4; |
| 133 | #endif |
| 134 | #if BYTE_ORDER == BIG_ENDIAN |
| 135 | uint8_t reserved : 4; |
| 136 | uint8_t chNum : 4; |
| 137 | #endif |
| 138 | } __attribute__((packed)); |
| 139 | |
| 140 | /** @struct GetChannelPayloadSupportResp |
| 141 | * |
| 142 | * Structure for get channel payload support command response (refer spec |
| 143 | * sec 24.8) |
| 144 | */ |
| 145 | struct GetChannelPayloadSupportResp |
| 146 | { |
| 147 | uint8_t stdPayloadType[2]; |
| 148 | uint8_t sessSetupPayloadType[2]; |
| 149 | uint8_t OEMPayloadType[2]; |
| 150 | uint8_t reserved[2]; |
| 151 | } __attribute__((packed)); |
| 152 | |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 153 | /** @brief implements the set channel access command |
| 154 | * @ param ctx - context pointer |
| 155 | * @ param channel - channel number |
| 156 | * @ param reserved - skip 4 bits |
| 157 | * @ param accessMode - access mode for IPMI messaging |
| 158 | * @ param usrAuth - user level authentication (enable/disable) |
| 159 | * @ param msgAuth - per message authentication (enable/disable) |
| 160 | * @ param alertDisabled - PEF alerting (enable/disable) |
| 161 | * @ param chanAccess - channel access |
| 162 | * @ param channelPrivLimit - channel privilege limit |
| 163 | * @ param reserved - skip 3 bits |
| 164 | * @ param channelPrivMode - channel priviledge mode |
| 165 | * |
| 166 | * @ returns IPMI completion code |
| 167 | **/ |
| 168 | RspType<> ipmiSetChannelAccess(Context::ptr ctx, uint4_t channel, |
| 169 | uint4_t reserved1, uint3_t accessMode, |
| 170 | bool usrAuth, bool msgAuth, bool alertDisabled, |
| 171 | uint2_t chanAccess, uint4_t channelPrivLimit, |
| 172 | uint2_t reserved2, uint2_t channelPrivMode) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 173 | { |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 174 | const uint8_t chNum = |
| 175 | convertCurrentChannelNum(static_cast<uint8_t>(channel), ctx->channel); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 176 | |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 177 | if (!isValidChannel(chNum) || reserved1 != 0 || reserved2 != 0) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 178 | { |
Richard Marian Thomaiyar | ef02401 | 2019-01-29 11:06:39 +0530 | [diff] [blame] | 179 | log<level::DEBUG>("Set channel access - Invalid field in request"); |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 180 | return responseInvalidFieldRequest(); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 181 | } |
| 182 | |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 183 | if (getChannelSessionSupport(chNum) == EChannelSessSupported::none) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 184 | { |
| 185 | log<level::DEBUG>("Set channel access - No support on channel"); |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 186 | return responseInvalidFieldRequest(); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | ChannelAccess chActData; |
| 190 | ChannelAccess chNVData; |
| 191 | uint8_t setActFlag = 0; |
| 192 | uint8_t setNVFlag = 0; |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 193 | Cc compCode; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 194 | |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 195 | // cannot static cast directly from uint2_t to enum; must go via int |
| 196 | uint8_t channelAccessAction = static_cast<uint8_t>(chanAccess); |
| 197 | switch (static_cast<EChannelActionType>(channelAccessAction)) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 198 | { |
| 199 | case doNotSet: |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 200 | break; |
| 201 | case nvData: |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 202 | chNVData.accessMode = static_cast<uint8_t>(accessMode); |
| 203 | chNVData.userAuthDisabled = usrAuth; |
| 204 | chNVData.perMsgAuthDisabled = msgAuth; |
| 205 | chNVData.alertingDisabled = alertDisabled; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 206 | setNVFlag |= (setAccessMode | setUserAuthEnabled | |
| 207 | setMsgAuthEnabled | setAlertingEnabled); |
| 208 | break; |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 209 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 210 | case activeData: |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 211 | chActData.accessMode = static_cast<uint8_t>(accessMode); |
| 212 | chActData.userAuthDisabled = usrAuth; |
| 213 | chActData.perMsgAuthDisabled = msgAuth; |
| 214 | chActData.alertingDisabled = alertDisabled; |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 215 | setActFlag |= (setAccessMode | setUserAuthEnabled | |
| 216 | setMsgAuthEnabled | setAlertingEnabled); |
| 217 | break; |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 218 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 219 | case reserved: |
| 220 | default: |
| 221 | log<level::DEBUG>("Set channel access - Invalid access set mode"); |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 222 | return responseInvalidFieldRequest(); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 223 | } |
| 224 | |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 225 | // cannot static cast directly from uint2_t to enum; must go via int |
| 226 | uint8_t channelPrivAction = static_cast<uint8_t>(channelPrivMode); |
| 227 | switch (static_cast<EChannelActionType>(channelPrivAction)) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 228 | { |
| 229 | case doNotSet: |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 230 | break; |
| 231 | case nvData: |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 232 | chNVData.privLimit = static_cast<uint8_t>(channelPrivLimit); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 233 | setNVFlag |= setPrivLimit; |
| 234 | break; |
| 235 | case activeData: |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 236 | chActData.privLimit = static_cast<uint8_t>(channelPrivLimit); |
| 237 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 238 | setActFlag |= setPrivLimit; |
| 239 | break; |
| 240 | case reserved: |
| 241 | default: |
| 242 | log<level::DEBUG>("Set channel access - Invalid access priv mode"); |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 243 | return responseInvalidFieldRequest(); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | if (setNVFlag != 0) |
| 247 | { |
| 248 | compCode = setChannelAccessPersistData(chNum, chNVData, setNVFlag); |
| 249 | if (compCode != IPMI_CC_OK) |
| 250 | { |
| 251 | log<level::DEBUG>("Set channel access - Failed to set access data"); |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 252 | return response(compCode); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | if (setActFlag != 0) |
| 257 | { |
| 258 | compCode = setChannelAccessData(chNum, chActData, setActFlag); |
| 259 | if (compCode != IPMI_CC_OK) |
| 260 | { |
| 261 | log<level::DEBUG>("Set channel access - Failed to set access data"); |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 262 | return response(compCode); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 266 | return responseSuccess(); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | ipmi_ret_t ipmiGetChannelAccess(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 270 | ipmi_request_t request, |
| 271 | ipmi_response_t response, |
| 272 | ipmi_data_len_t data_len, |
| 273 | ipmi_context_t context) |
| 274 | { |
Richard Marian Thomaiyar | 48e5558 | 2018-12-20 15:58:04 +0530 | [diff] [blame] | 275 | const GetChannelAccessReq* req = static_cast<GetChannelAccessReq*>(request); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 276 | size_t reqLength = *data_len; |
| 277 | |
| 278 | *data_len = 0; |
| 279 | |
| 280 | if (reqLength != sizeof(*req)) |
| 281 | { |
| 282 | log<level::DEBUG>("Get channel access - Invalid Length"); |
| 283 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 284 | } |
| 285 | |
Richard Marian Thomaiyar | f1d0e23 | 2018-12-08 17:36:20 +0530 | [diff] [blame] | 286 | uint8_t chNum = convertCurrentChannelNum(req->chNum); |
Richard Marian Thomaiyar | ef02401 | 2019-01-29 11:06:39 +0530 | [diff] [blame] | 287 | if (!isValidChannel(chNum) || req->reserved_1 != 0 || req->reserved_2 != 0) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 288 | { |
Richard Marian Thomaiyar | ef02401 | 2019-01-29 11:06:39 +0530 | [diff] [blame] | 289 | log<level::DEBUG>("Get channel access - Invalid field in request"); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 290 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 291 | } |
| 292 | |
| 293 | if ((req->accessSetMode == doNotSet) || (req->accessSetMode == reserved)) |
| 294 | { |
| 295 | log<level::DEBUG>("Get channel access - Invalid Access mode"); |
| 296 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 297 | } |
| 298 | |
| 299 | if (EChannelSessSupported::none == getChannelSessionSupport(chNum)) |
| 300 | { |
| 301 | log<level::DEBUG>("Get channel access - No support on channel"); |
| 302 | return IPMI_CC_ACTION_NOT_SUPPORTED_FOR_CHANNEL; |
| 303 | } |
| 304 | |
Richard Marian Thomaiyar | 48e5558 | 2018-12-20 15:58:04 +0530 | [diff] [blame] | 305 | GetChannelAccessResp* resp = static_cast<GetChannelAccessResp*>(response); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 306 | |
| 307 | std::fill(reinterpret_cast<uint8_t*>(resp), |
| 308 | reinterpret_cast<uint8_t*>(resp) + sizeof(*resp), 0); |
| 309 | |
| 310 | ChannelAccess chAccess; |
| 311 | ipmi_ret_t compCode = IPMI_CC_OK; |
| 312 | |
| 313 | if (req->accessSetMode == nvData) |
| 314 | { |
| 315 | compCode = getChannelAccessPersistData(chNum, chAccess); |
| 316 | } |
| 317 | else if (req->accessSetMode == activeData) |
| 318 | { |
| 319 | compCode = getChannelAccessData(chNum, chAccess); |
| 320 | } |
| 321 | |
| 322 | if (compCode != IPMI_CC_OK) |
| 323 | { |
| 324 | return compCode; |
| 325 | } |
| 326 | |
| 327 | resp->accessMode = chAccess.accessMode; |
| 328 | resp->usrAuthDisabled = chAccess.userAuthDisabled; |
| 329 | resp->msgAuthDisabled = chAccess.perMsgAuthDisabled; |
| 330 | resp->alertDisabled = chAccess.alertingDisabled; |
| 331 | resp->privLimit = chAccess.privLimit; |
| 332 | |
| 333 | *data_len = sizeof(*resp); |
| 334 | return IPMI_CC_OK; |
| 335 | } |
| 336 | |
| 337 | ipmi_ret_t ipmiGetChannelInfo(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 338 | ipmi_request_t request, ipmi_response_t response, |
| 339 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 340 | { |
Richard Marian Thomaiyar | 48e5558 | 2018-12-20 15:58:04 +0530 | [diff] [blame] | 341 | const GetChannelInfoReq* req = static_cast<GetChannelInfoReq*>(request); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 342 | size_t reqLength = *data_len; |
| 343 | |
| 344 | *data_len = 0; |
| 345 | |
| 346 | if (reqLength != sizeof(*req)) |
| 347 | { |
| 348 | log<level::DEBUG>("Get channel info - Invalid Length"); |
| 349 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 350 | } |
| 351 | |
Richard Marian Thomaiyar | f1d0e23 | 2018-12-08 17:36:20 +0530 | [diff] [blame] | 352 | uint8_t chNum = convertCurrentChannelNum(req->chNum); |
Richard Marian Thomaiyar | ef02401 | 2019-01-29 11:06:39 +0530 | [diff] [blame] | 353 | if (!isValidChannel(chNum) || req->reserved_1 != 0) |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 354 | { |
Richard Marian Thomaiyar | ef02401 | 2019-01-29 11:06:39 +0530 | [diff] [blame] | 355 | log<level::DEBUG>("Get channel info - Invalid field in request"); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 356 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 357 | } |
| 358 | |
| 359 | // Check the existance of device for session-less channels. |
| 360 | if ((EChannelSessSupported::none != getChannelSessionSupport(chNum)) && |
| 361 | (!(doesDeviceExist(chNum)))) |
| 362 | { |
| 363 | log<level::DEBUG>("Get channel info - Device not exist"); |
| 364 | return IPMI_CC_PARM_OUT_OF_RANGE; |
| 365 | } |
| 366 | |
Richard Marian Thomaiyar | 48e5558 | 2018-12-20 15:58:04 +0530 | [diff] [blame] | 367 | GetChannelInfoResp* resp = static_cast<GetChannelInfoResp*>(response); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 368 | |
| 369 | std::fill(reinterpret_cast<uint8_t*>(resp), |
| 370 | reinterpret_cast<uint8_t*>(resp) + sizeof(*resp), 0); |
| 371 | |
| 372 | ChannelInfo chInfo; |
| 373 | ipmi_ret_t compCode = getChannelInfo(chNum, chInfo); |
| 374 | if (compCode != IPMI_CC_OK) |
| 375 | { |
| 376 | return compCode; |
| 377 | } |
| 378 | |
| 379 | resp->chNum = chNum; |
| 380 | resp->mediumType = chInfo.mediumType; |
| 381 | resp->msgProtType = chInfo.protocolType; |
| 382 | resp->actSessCount = getChannelActiveSessions(chNum); |
| 383 | resp->sessType = chInfo.sessionSupported; |
| 384 | |
| 385 | // IPMI Spec: The IPMI Enterprise Number is: 7154 (decimal) |
| 386 | resp->vendorId[0] = 0xF2; |
| 387 | resp->vendorId[1] = 0x1B; |
| 388 | resp->vendorId[2] = 0x00; |
| 389 | |
| 390 | // Auxiliary Channel info - byte 1:2 |
| 391 | // TODO: For System Interface(0xF) and OEM channel types, this needs |
| 392 | // to be changed acoordingly. |
| 393 | // All other channel types, its reverved |
| 394 | resp->auxChInfo[0] = 0x00; |
| 395 | resp->auxChInfo[1] = 0x00; |
| 396 | |
| 397 | *data_len = sizeof(*resp); |
| 398 | |
| 399 | return IPMI_CC_OK; |
| 400 | } |
| 401 | |
Saravanan Palanisamy | b5a0f16 | 2019-03-04 18:34:44 +0530 | [diff] [blame] | 402 | ipmi_ret_t ipmiGetChannelPayloadSupport(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 403 | ipmi_request_t request, |
| 404 | ipmi_response_t response, |
| 405 | ipmi_data_len_t data_len, |
| 406 | ipmi_context_t context) |
| 407 | { |
| 408 | const auto req = static_cast<GetChannelPayloadSupportReq*>(request); |
| 409 | size_t reqLength = *data_len; |
| 410 | |
| 411 | *data_len = 0; |
| 412 | |
| 413 | if (reqLength != sizeof(*req)) |
| 414 | { |
| 415 | log<level::DEBUG>("Get channel payload - Invalid Length"); |
| 416 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 417 | } |
| 418 | |
| 419 | uint8_t chNum = convertCurrentChannelNum(req->chNum); |
| 420 | if (!isValidChannel(chNum) || req->reserved != 0) |
| 421 | { |
| 422 | log<level::DEBUG>("Get channel payload - Invalid field in request"); |
| 423 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 424 | } |
| 425 | |
| 426 | // Not supported on sessionless channels. |
| 427 | if (EChannelSessSupported::none == getChannelSessionSupport(chNum)) |
| 428 | { |
| 429 | log<level::DEBUG>("Get channel payload - Sessionless Channel"); |
| 430 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 431 | } |
| 432 | |
| 433 | // Session support is available in active LAN channels. |
| 434 | if ((EChannelSessSupported::none != getChannelSessionSupport(chNum)) && |
| 435 | (!(doesDeviceExist(chNum)))) |
| 436 | { |
| 437 | log<level::DEBUG>("Get channel payload - Device not exist"); |
| 438 | return IPMI_CC_INVALID_FIELD_REQUEST; |
| 439 | } |
| 440 | |
| 441 | auto resp = static_cast<GetChannelPayloadSupportResp*>(response); |
| 442 | |
| 443 | std::fill(reinterpret_cast<uint8_t*>(resp), |
| 444 | reinterpret_cast<uint8_t*>(resp) + sizeof(*resp), 0); |
| 445 | |
| 446 | // TODO: Hard coding for now. |
| 447 | // Mapping PayloadTypes to 'GetChannelPayloadSupportResp' fields: |
| 448 | // -------------------------------------------------------------- |
| 449 | // Mask all except least 3 significant bits to get a value in the range of |
| 450 | // 0-7. This value maps to the bit position of given payload type in 'resp' |
| 451 | // fields. |
| 452 | |
| 453 | static constexpr uint8_t payloadByteMask = 0x07; |
| 454 | static constexpr uint8_t stdPayloadTypeIPMI = |
| 455 | 1 << (static_cast<uint8_t>(PayloadType::IPMI) & payloadByteMask); |
| 456 | static constexpr uint8_t stdPayloadTypeSOL = |
| 457 | 1 << (static_cast<uint8_t>(PayloadType::SOL) & payloadByteMask); |
| 458 | |
| 459 | static constexpr uint8_t sessPayloadTypeOpenReq = |
| 460 | 1 << (static_cast<uint8_t>(PayloadType::OPEN_SESSION_REQUEST) & |
| 461 | payloadByteMask); |
| 462 | static constexpr uint8_t sessPayloadTypeRAKP1 = |
| 463 | 1 << (static_cast<uint8_t>(PayloadType::RAKP1) & payloadByteMask); |
| 464 | static constexpr uint8_t sessPayloadTypeRAKP3 = |
| 465 | 1 << (static_cast<uint8_t>(PayloadType::RAKP3) & payloadByteMask); |
| 466 | |
| 467 | resp->stdPayloadType[0] = stdPayloadTypeIPMI | stdPayloadTypeSOL; |
| 468 | // RMCP+ Open Session request, RAKP Message1 and RAKP Message3. |
| 469 | resp->sessSetupPayloadType[0] = |
| 470 | sessPayloadTypeOpenReq | sessPayloadTypeRAKP1 | sessPayloadTypeRAKP3; |
| 471 | |
| 472 | *data_len = sizeof(*resp); |
| 473 | |
| 474 | return IPMI_CC_OK; |
| 475 | } |
| 476 | |
William A. Kennington III | 343d061 | 2018-12-10 15:56:24 -0800 | [diff] [blame] | 477 | void registerChannelFunctions() __attribute__((constructor)); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 478 | void registerChannelFunctions() |
| 479 | { |
| 480 | ipmiChannelInit(); |
| 481 | |
NITIN SHARMA | 89e4bf2 | 2019-05-02 13:03:58 +0000 | [diff] [blame^] | 482 | registerHandler(prioOpenBmcBase, netFnApp, app::cmdSetChannelAccess, |
| 483 | Privilege::Admin, ipmiSetChannelAccess); |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 484 | |
| 485 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHANNEL_ACCESS, NULL, |
| 486 | ipmiGetChannelAccess, PRIVILEGE_USER); |
| 487 | |
| 488 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHANNEL_INFO, NULL, |
| 489 | ipmiGetChannelInfo, PRIVILEGE_USER); |
Saravanan Palanisamy | b5a0f16 | 2019-03-04 18:34:44 +0530 | [diff] [blame] | 490 | |
| 491 | ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHANNEL_PAYLOAD_SUPPORT, |
| 492 | NULL, ipmiGetChannelPayloadSupport, PRIVILEGE_USER); |
| 493 | |
AppaRao Puli | 071f3f2 | 2018-05-24 16:45:30 +0530 | [diff] [blame] | 494 | return; |
| 495 | } |
| 496 | |
| 497 | } // namespace ipmi |