blob: f9c00b52a2b81947b4e47e7b0116c93d65626b37 [file] [log] [blame]
Tom Joseph3e61aa02016-08-08 08:42:39 -05001#pragma once
2
Vernon Mauery9e801a22018-10-12 13:20:49 -07003#include "session.hpp"
4
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +05305#include <ipmid/api.hpp>
6#include <ipmid/sessiondef.hpp>
Tom Joseph3e61aa02016-08-08 08:42:39 -05007#include <map>
8#include <memory>
9#include <mutex>
10
Tom Joseph3e61aa02016-08-08 08:42:39 -050011namespace session
12{
13
14enum class RetrieveOption
15{
16 BMC_SESSION_ID,
17 RC_SESSION_ID,
18};
19
Tom Joseph3563f8f2017-05-08 15:42:54 +053020/**
Tom Joseph3e61aa02016-08-08 08:42:39 -050021 * @class Manager
22 *
23 * Manager class acts a manager for the IPMI sessions and provides interfaces
24 * to start a session, stop a session and get reference to the session objects.
25 *
26 */
27
28class Manager
29{
Vernon Mauery9e801a22018-10-12 13:20:49 -070030 public:
31 // BMC Session ID is the key for the map
32 using SessionMap = std::map<SessionID, std::shared_ptr<Session>>;
Tom Joseph3e61aa02016-08-08 08:42:39 -050033
Vernon Mauery9e801a22018-10-12 13:20:49 -070034 Manager();
35 ~Manager() = default;
36 Manager(const Manager&) = delete;
37 Manager& operator=(const Manager&) = delete;
38 Manager(Manager&&) = default;
39 Manager& operator=(Manager&&) = default;
Tom Joseph3e61aa02016-08-08 08:42:39 -050040
Vernon Mauery9e801a22018-10-12 13:20:49 -070041 /**
42 * @brief Start an IPMI session
43 *
44 * @param[in] remoteConsoleSessID - Remote Console Session ID mentioned
45 * in the Open SessionRequest Command
46 * @param[in] priv - Privilege level requested
47 * @param[in] authAlgo - Authentication Algorithm
48 * @param[in] intAlgo - Integrity Algorithm
49 * @param[in] cryptAlgo - Confidentiality Algorithm
50 *
51 * @return session handle on success and nullptr on failure
52 *
53 */
Vernon Maueryae1fda42018-10-15 12:55:34 -070054 std::shared_ptr<Session>
55 startSession(SessionID remoteConsoleSessID, Privilege priv,
56 cipher::rakp_auth::Algorithms authAlgo,
57 cipher::integrity::Algorithms intAlgo,
58 cipher::crypt::Algorithms cryptAlgo);
Tom Joseph3e61aa02016-08-08 08:42:39 -050059
Vernon Mauery9e801a22018-10-12 13:20:49 -070060 /**
61 * @brief Stop IPMI Session
62 *
63 * @param[in] bmcSessionID - BMC Session ID
64 *
65 * @return true on success and failure if session ID is invalid
66 *
67 */
68 bool stopSession(SessionID bmcSessionID);
Tom Joseph3e61aa02016-08-08 08:42:39 -050069
Vernon Mauery9e801a22018-10-12 13:20:49 -070070 /**
71 * @brief Get Session Handle
72 *
73 * @param[in] sessionID - Session ID
74 * @param[in] option - Select between BMC Session ID and Remote Console
75 * Session ID, Default option is BMC Session ID
76 *
77 * @return session handle on success and nullptr on failure
78 *
79 */
Vernon Maueryae1fda42018-10-15 12:55:34 -070080 std::shared_ptr<Session>
Vernon Mauery9e801a22018-10-12 13:20:49 -070081 getSession(SessionID sessionID,
82 RetrieveOption option = RetrieveOption::BMC_SESSION_ID);
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +053083 uint8_t getActiveSessionCount() const;
84 uint8_t getSessionHandle(SessionID bmcSessionID) const;
85 uint8_t storeSessionHandle(SessionID bmcSessionID);
86 uint32_t getSessionIDbyHandle(uint8_t sessionHandle) const;
87
88 void managerInit(const std::string& channel);
89
90 uint8_t getNetworkInstance(void);
Tom Joseph3e61aa02016-08-08 08:42:39 -050091
Vernon Mauery9e801a22018-10-12 13:20:49 -070092 private:
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +053093 //+1 for session, as 0 is reserved for sessionless command
94 std::array<uint32_t, session::maxSessionCountPerChannel + 1>
95 sessionHandleMap = {0};
96
Vernon Mauery9e801a22018-10-12 13:20:49 -070097 /**
98 * @brief Session Manager keeps the session objects as a sorted
99 * associative container with Session ID as the unique key
100 */
101 SessionMap sessionsMap;
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +0530102 std::unique_ptr<sdbusplus::server::manager::manager> objManager = nullptr;
103 std::string chName{}; // Channel Name
104 uint8_t ipmiNetworkInstance;
Vernon Mauery9e801a22018-10-12 13:20:49 -0700105 /**
106 * @brief Clean Session Stale Entries
107 *
108 * Removes the inactive sessions entries from the Session Map
109 */
110 void cleanStaleEntries();
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +0530111 void setNetworkInstance(void);
Tom Joseph3e61aa02016-08-08 08:42:39 -0500112};
113
114} // namespace session