blob: f30ef781d4b966cac93b21cefc9d374d8204ed06 [file] [log] [blame]
Tom Joseph9662c3a2016-12-06 17:52:16 +05301#include "session_cmds.hpp"
2
3#include <iostream>
4
5#include "endian.hpp"
6#include "main.hpp"
7#include <host-ipmid/ipmid-api.h>
8
9namespace command
10{
11
12std::vector<uint8_t> setSessionPrivilegeLevel(std::vector<uint8_t>& inPayload,
13 const message::Handler& handler)
14{
15 std::cout << ">> setSessionPrivilegeLevel\n";
16
17 std::vector<uint8_t> outPayload(sizeof(SetSessionPrivLevelResp));
18 auto request = reinterpret_cast<SetSessionPrivLevelReq*>(inPayload.data());
19 auto response = reinterpret_cast<SetSessionPrivLevelResp*>
20 (outPayload.data());
21 response->completionCode = IPMI_CC_OK;
22 uint8_t reqPrivilegeLevel = request->reqPrivLevel;
23
24 auto session = (std::get<session::Manager&>(singletonPool).getSession(
25 handler.sessionID)).lock();
26
27 if (reqPrivilegeLevel == 0) // Just return present privilege level
28 {
29 response->newPrivLevel = static_cast<uint8_t>(session->curPrivLevel);
30 }
31 else if (reqPrivilegeLevel <= static_cast<uint8_t>(session->maxPrivLevel))
32 {
33 session->curPrivLevel = static_cast<session::Privilege>
34 (reqPrivilegeLevel);
35 response->newPrivLevel = reqPrivilegeLevel;
36 }
37 else
38 {
39 // Requested level exceeds Channel and/or User Privilege Limit
40 response->completionCode = IPMI_CC_EXCEEDS_USER_PRIV;
41 }
42
43 std::cout << "<< setSessionPrivilegeLevel\n";
44 return outPayload;
45}
46
47std::vector<uint8_t> closeSession(std::vector<uint8_t>& inPayload,
48 const message::Handler& handler)
49{
50 std::cout << ">> closeSession\n";
51
52 std::vector<uint8_t> outPayload(sizeof(CloseSessionResponse));
53 auto request = reinterpret_cast<CloseSessionRequest*>(inPayload.data());
54 auto response = reinterpret_cast<CloseSessionResponse*>(outPayload.data());
55 response->completionCode = IPMI_CC_OK ;
56
57 auto bmcSessionID = endian::from_ipmi(request->sessionID);
58
59 // Session 0 is needed to handle session setup, so session zero is never
60 // closed
61 if (bmcSessionID == session::SESSION_ZERO)
62 {
63 response->completionCode = IPMI_CC_INVALID_SESSIONID;
64 }
65 else
66 {
67 auto status = std::get<session::Manager&>(singletonPool).stopSession
68 (bmcSessionID);
69 if(!status)
70 {
71 response->completionCode = IPMI_CC_INVALID_SESSIONID;
72 }
73 }
74
75 std::cout << "<< closeSession\n";
76 return outPayload;
77}
78
79} // namespace command