diff options
author | Rajashekar Gade Reddy <raja.sekhar.reddy.gade@linux.intel.com> | 2019-07-10 16:54:55 +0000 |
---|---|---|
committer | Vernon Mauery <vernon.mauery@linux.intel.com> | 2019-09-25 17:42:56 +0000 |
commit | e7023926675030a5976dffda0825445ca0b5ef84 (patch) | |
tree | c333de2b8fea9d8284e239e8303be5d599df6377 /include/ipmid | |
parent | d7dadc27792747c00c3bfef4fc45d6f3184ba815 (diff) | |
download | phosphor-host-ipmid-e7023926675030a5976dffda0825445ca0b5ef84.tar.gz phosphor-host-ipmid-e7023926675030a5976dffda0825445ca0b5ef84.zip |
Implemented close session cmd in host interface
This command can close any session via host interface.
Tested:
Close the existing valid session by session id
ipmitool raw 0x6 0x3c <valid sesssion id >
Response : 00 // success
Close the existing valid session by session handle
ipmitool raw 0x6 0x3c <zero session id> <valid session handle>
Response : 00 // success
Close the session by zero session id
ipmitool raw 0x6 0x3c <zero session id>
Response : 0x87 // inavlid session id
Close the session by zero session handle
ipmitool raw 0x6 0x3c <zero session id> <zero session handle>
Response : 0x88 // inavlid session handle
Close an inactive session.
ipmitool raw 0x6 0x3c <valid session id>
Response : 0xcc // invalid data field in request
Close an inactive session.
ipmitool raw 0x6 0x3c <zero session id> <valid session hnadle>
Response : 0xcc // invalid data field in request
Signed-off-by: Rajashekar Gade Reddy <raja.sekhar.reddy.gade@linux.intel.com>
Change-Id: I8af290001d8effbbcdbbe2dd93aabf1b015e7a88
Diffstat (limited to 'include/ipmid')
-rw-r--r-- | include/ipmid/sessiondef.hpp | 3 | ||||
-rw-r--r-- | include/ipmid/sessionhelper.hpp | 88 |
2 files changed, 91 insertions, 0 deletions
diff --git a/include/ipmid/sessiondef.hpp b/include/ipmid/sessiondef.hpp index 9fce256..48ee4c6 100644 --- a/include/ipmid/sessiondef.hpp +++ b/include/ipmid/sessiondef.hpp @@ -28,7 +28,10 @@ static constexpr size_t sessionZero = 0; static constexpr size_t maxSessionlessCount = 1; static constexpr uint8_t invalidSessionID = 0; static constexpr uint8_t invalidSessionHandle = 0; +static constexpr uint8_t defaultSessionHandle = 0xFF; static constexpr uint8_t maxNetworkInstanceSupported = 4; +static constexpr uint8_t ccInvalidSessionId = 0x87; +static constexpr uint8_t ccInvalidSessionHandle = 0x88; // MSB BIT 7 BIT 6 assigned for netipmid instance in session handle. static constexpr uint8_t multiIntfaceSessionHandleMask = 0x3F; diff --git a/include/ipmid/sessionhelper.hpp b/include/ipmid/sessionhelper.hpp new file mode 100644 index 0000000..a96f037 --- /dev/null +++ b/include/ipmid/sessionhelper.hpp @@ -0,0 +1,88 @@ +#include <sstream> +#include <string> + +/** + * @brief parse session input payload. + * + * This function retrives the session id and session handle from the session + * object path. + * A valid object path will be in the form + * "/xyz/openbmc_project/ipmi/session/channel/sessionId_sessionHandle" + * + * Ex: "/xyz/openbmc_project/ipmi/session/eth0/12a4567d_8a" + * SessionId : 0X12a4567d + * SessionHandle: 0X8a + + * @param[in] objectPath - session object path + * @param[in] sessionId - retrived session id will be asigned. + * @param[in] sessionHandle - retrived session handle will be asigned. + * + * @return true if session id and session handle are retrived else returns + * false. + */ +bool parseCloseSessionInputPayload(const std::string& objectPath, + uint32_t& sessionId, uint8_t& sessionHandle) +{ + if (objectPath.empty()) + { + return false; + } + // getting the position of session id and session handle string from + // object path. + std::size_t ptrPosition = objectPath.rfind("/"); + uint16_t tempSessionHandle = 0; + + if (ptrPosition != std::string::npos) + { + // get the sessionid & session handle string from the session object + // path Ex: sessionIdString: "12a4567d_8a" + std::string sessionIdString = objectPath.substr(ptrPosition + 1); + std::size_t pos = sessionIdString.rfind("_"); + + if (pos != std::string::npos) + { + // extracting the session handle + std::string sessionHandleString = sessionIdString.substr(pos + 1); + // extracting the session id + sessionIdString = sessionIdString.substr(0, pos); + // converting session id string and session handle string to + // hexadecimal. + std::stringstream handle(sessionHandleString); + handle >> std::hex >> tempSessionHandle; + sessionHandle = tempSessionHandle & 0xFF; + std::stringstream idString(sessionIdString); + idString >> std::hex >> sessionId; + return true; + } + } + return false; +} + +/** + * @brief is session object matched. + * + * This function checks whether the objectPath contains reqSessionId and + * reqSessionHandle, e.g., "/xyz/openbmc_project/ipmi/session/eth0/12a4567d_8a" + * matches sessionId 0x12a4567d and sessionHandle 0x8a. + * + * @param[in] objectPath - session object path + * @param[in] reqSessionId - request session id + * @param[in] reqSessionHandle - request session handle + * + * @return true if the object is matched else return false + **/ +bool isSessionObjectMatched(const std::string objectPath, + const uint32_t reqSessionId, + const uint8_t reqSessionHandle) +{ + uint32_t sessionId = 0; + uint8_t sessionHandle = 0; + + if (parseCloseSessionInputPayload(objectPath, sessionId, sessionHandle)) + { + return (reqSessionId == sessionId) || + (reqSessionHandle == sessionHandle); + } + + return false; +} |