Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 1 | #include "session_cmds.hpp" |
| 2 | |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 3 | #include "endian.hpp" |
| 4 | #include "main.hpp" |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 5 | |
William A. Kennington III | 4f09eae | 2019-02-12 17:10:35 -0800 | [diff] [blame] | 6 | #include <ipmid/api.h> |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 7 | |
| 8 | namespace command |
| 9 | { |
| 10 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 11 | std::vector<uint8_t> |
| 12 | setSessionPrivilegeLevel(const std::vector<uint8_t>& inPayload, |
| 13 | const message::Handler& handler) |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 14 | { |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 15 | |
| 16 | std::vector<uint8_t> outPayload(sizeof(SetSessionPrivLevelResp)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 17 | auto request = |
| 18 | reinterpret_cast<const SetSessionPrivLevelReq*>(inPayload.data()); |
| 19 | auto response = |
| 20 | reinterpret_cast<SetSessionPrivLevelResp*>(outPayload.data()); |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 21 | response->completionCode = IPMI_CC_OK; |
| 22 | uint8_t reqPrivilegeLevel = request->reqPrivLevel; |
| 23 | |
Vernon Mauery | ae1fda4 | 2018-10-15 12:55:34 -0700 | [diff] [blame] | 24 | auto session = std::get<session::Manager&>(singletonPool) |
| 25 | .getSession(handler.sessionID); |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 26 | |
| 27 | if (reqPrivilegeLevel == 0) // Just return present privilege level |
| 28 | { |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame^] | 29 | response->newPrivLevel = session->currentPrivilege(); |
Richard Marian Thomaiyar | 127748a | 2018-09-06 07:08:51 +0530 | [diff] [blame] | 30 | return outPayload; |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 31 | } |
Tom Joseph | 4021b1f | 2019-02-12 10:10:12 +0530 | [diff] [blame] | 32 | if (reqPrivilegeLevel > (static_cast<uint8_t>(session->reqMaxPrivLevel) & |
| 33 | session::reqMaxPrivMask)) |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 34 | { |
Richard Marian Thomaiyar | 127748a | 2018-09-06 07:08:51 +0530 | [diff] [blame] | 35 | // Requested level exceeds Channel and/or User Privilege Limit |
| 36 | response->completionCode = IPMI_CC_EXCEEDS_USER_PRIV; |
| 37 | return outPayload; |
| 38 | } |
Richard Marian Thomaiyar | 127748a | 2018-09-06 07:08:51 +0530 | [diff] [blame] | 39 | // Use the minimum privilege of user or channel |
| 40 | uint8_t minPriv = 0; |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 41 | if (session->sessionChannelAccess.privLimit < |
| 42 | session->sessionUserPrivAccess.privilege) |
Richard Marian Thomaiyar | 127748a | 2018-09-06 07:08:51 +0530 | [diff] [blame] | 43 | { |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 44 | minPriv = session->sessionChannelAccess.privLimit; |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 45 | } |
| 46 | else |
| 47 | { |
Richard Marian Thomaiyar | 992e53c | 2019-03-03 13:30:46 +0530 | [diff] [blame] | 48 | minPriv = session->sessionUserPrivAccess.privilege; |
Richard Marian Thomaiyar | 127748a | 2018-09-06 07:08:51 +0530 | [diff] [blame] | 49 | } |
| 50 | if (reqPrivilegeLevel > minPriv) |
| 51 | { |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 52 | // Requested level exceeds Channel and/or User Privilege Limit |
| 53 | response->completionCode = IPMI_CC_EXCEEDS_USER_PRIV; |
| 54 | } |
Richard Marian Thomaiyar | 127748a | 2018-09-06 07:08:51 +0530 | [diff] [blame] | 55 | else |
| 56 | { |
| 57 | // update current privilege of the session. |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame^] | 58 | session->currentPrivilege(static_cast<uint8_t>(reqPrivilegeLevel)); |
Richard Marian Thomaiyar | 127748a | 2018-09-06 07:08:51 +0530 | [diff] [blame] | 59 | response->newPrivLevel = reqPrivilegeLevel; |
| 60 | } |
| 61 | |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 62 | return outPayload; |
| 63 | } |
| 64 | |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 65 | std::vector<uint8_t> closeSession(const std::vector<uint8_t>& inPayload, |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 66 | const message::Handler& handler) |
| 67 | { |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 68 | std::vector<uint8_t> outPayload(sizeof(CloseSessionResponse)); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 69 | auto request = |
| 70 | reinterpret_cast<const CloseSessionRequest*>(inPayload.data()); |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 71 | auto response = reinterpret_cast<CloseSessionResponse*>(outPayload.data()); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 72 | response->completionCode = IPMI_CC_OK; |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 73 | |
| 74 | auto bmcSessionID = endian::from_ipmi(request->sessionID); |
| 75 | |
| 76 | // Session 0 is needed to handle session setup, so session zero is never |
| 77 | // closed |
Suryakanth Sekar | f8a34fc | 2019-06-12 20:59:18 +0530 | [diff] [blame^] | 78 | if (bmcSessionID == session::sessionZero) |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 79 | { |
| 80 | response->completionCode = IPMI_CC_INVALID_SESSIONID; |
| 81 | } |
| 82 | else |
| 83 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 84 | auto status = std::get<session::Manager&>(singletonPool) |
| 85 | .stopSession(bmcSessionID); |
| 86 | if (!status) |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 87 | { |
| 88 | response->completionCode = IPMI_CC_INVALID_SESSIONID; |
| 89 | } |
| 90 | } |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 91 | return outPayload; |
| 92 | } |
| 93 | |
| 94 | } // namespace command |