Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <map> |
| 4 | #include <memory> |
| 5 | #include <mutex> |
| 6 | |
| 7 | #include "session.hpp" |
| 8 | |
| 9 | namespace session |
| 10 | { |
| 11 | |
| 12 | enum class RetrieveOption |
| 13 | { |
| 14 | BMC_SESSION_ID, |
| 15 | RC_SESSION_ID, |
| 16 | }; |
| 17 | |
| 18 | constexpr size_t SESSION_ZERO = 0; |
| 19 | constexpr size_t MAX_SESSIONLESS_COUNT = 1; |
| 20 | constexpr size_t MAX_SESSION_COUNT = 5; |
| 21 | |
Tom Joseph | 3563f8f | 2017-05-08 15:42:54 +0530 | [diff] [blame^] | 22 | /** |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 23 | * @class Manager |
| 24 | * |
| 25 | * Manager class acts a manager for the IPMI sessions and provides interfaces |
| 26 | * to start a session, stop a session and get reference to the session objects. |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | class Manager |
| 31 | { |
| 32 | public: |
| 33 | |
| 34 | // BMC Session ID is the key for the map |
| 35 | using SessionMap = std::map<SessionID, std::shared_ptr<Session>>; |
| 36 | |
| 37 | Manager(); |
| 38 | ~Manager() = default; |
| 39 | Manager(const Manager&) = delete; |
| 40 | Manager& operator=(const Manager&) = delete; |
| 41 | Manager(Manager&&) = default; |
| 42 | Manager& operator=(Manager&&) = default; |
| 43 | |
Tom Joseph | 3563f8f | 2017-05-08 15:42:54 +0530 | [diff] [blame^] | 44 | /** |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 45 | * @brief Start an IPMI session |
| 46 | * |
| 47 | * @param[in] remoteConsoleSessID - Remote Console Session ID mentioned |
| 48 | * in the Open SessionRequest Command |
| 49 | * @param[in] priv - Privilege level requested |
| 50 | * @param[in] authAlgo - Authentication Algorithm |
Tom Joseph | dd1be1a | 2017-01-10 16:10:29 +0530 | [diff] [blame] | 51 | * @param[in] intAlgo - Integrity Algorithm |
Tom Joseph | ba11f79 | 2017-01-24 18:21:45 +0530 | [diff] [blame] | 52 | * @param[in] cryptAlgo - Confidentiality Algorithm |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 53 | * |
| 54 | * @return session handle on success and nullptr on failure |
| 55 | * |
| 56 | */ |
| 57 | std::weak_ptr<Session> startSession(SessionID remoteConsoleSessID, |
Tom Joseph | dd1be1a | 2017-01-10 16:10:29 +0530 | [diff] [blame] | 58 | Privilege priv, cipher::rakp_auth::Algorithms authAlgo, |
Tom Joseph | ba11f79 | 2017-01-24 18:21:45 +0530 | [diff] [blame] | 59 | cipher::integrity::Algorithms intAlgo, |
| 60 | cipher::crypt::Algorithms cryptAlgo); |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 61 | |
Tom Joseph | 3563f8f | 2017-05-08 15:42:54 +0530 | [diff] [blame^] | 62 | /** |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 63 | * @brief Stop IPMI Session |
| 64 | * |
| 65 | * @param[in] bmcSessionID - BMC Session ID |
| 66 | * |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 67 | * @return true on success and failure if session ID is invalid |
| 68 | * |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 69 | */ |
Tom Joseph | 9662c3a | 2016-12-06 17:52:16 +0530 | [diff] [blame] | 70 | bool stopSession(SessionID bmcSessionID); |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 71 | |
Tom Joseph | 3563f8f | 2017-05-08 15:42:54 +0530 | [diff] [blame^] | 72 | /** |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 73 | * @brief Get Session Handle |
| 74 | * |
| 75 | * @param[in] sessionID - Session ID |
| 76 | * @param[in] option - Select between BMC Session ID and Remote Console |
| 77 | * Session ID, Default option is BMC Session ID |
| 78 | * |
| 79 | * @return session handle on success and nullptr on failure |
| 80 | * |
| 81 | */ |
| 82 | std::weak_ptr<Session> getSession( |
| 83 | SessionID sessionID, |
| 84 | RetrieveOption option = RetrieveOption::BMC_SESSION_ID); |
| 85 | |
| 86 | private: |
| 87 | |
Tom Joseph | 3563f8f | 2017-05-08 15:42:54 +0530 | [diff] [blame^] | 88 | /** |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 89 | * @brief Session Manager keeps the session objects as a sorted |
| 90 | * associative container with Session ID as the unique key |
| 91 | */ |
| 92 | SessionMap sessionsMap; |
| 93 | |
Tom Joseph | 3563f8f | 2017-05-08 15:42:54 +0530 | [diff] [blame^] | 94 | /** |
Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 95 | * @brief Clean Session Stale Entries |
| 96 | * |
| 97 | * Removes the inactive sessions entries from the Session Map |
| 98 | */ |
| 99 | void cleanStaleEntries(); |
| 100 | }; |
| 101 | |
| 102 | } // namespace session |