| Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 1 | #pragma once | 
 | 2 |  | 
| Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 3 | #include "session.hpp" | 
 | 4 |  | 
| Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 5 | #include <map> | 
 | 6 | #include <memory> | 
 | 7 | #include <mutex> | 
 | 8 |  | 
| Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 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 | { | 
| Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 32 |   public: | 
 | 33 |     // BMC Session ID is the key for the map | 
 | 34 |     using SessionMap = std::map<SessionID, std::shared_ptr<Session>>; | 
| Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 35 |  | 
| Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 36 |     Manager(); | 
 | 37 |     ~Manager() = default; | 
 | 38 |     Manager(const Manager&) = delete; | 
 | 39 |     Manager& operator=(const Manager&) = delete; | 
 | 40 |     Manager(Manager&&) = default; | 
 | 41 |     Manager& operator=(Manager&&) = default; | 
| Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 42 |  | 
| Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 43 |     /** | 
 | 44 |      * @brief Start an IPMI session | 
 | 45 |      * | 
 | 46 |      * @param[in] remoteConsoleSessID - Remote Console Session ID mentioned | 
 | 47 |      *            in the Open SessionRequest Command | 
 | 48 |      * @param[in] priv - Privilege level requested | 
 | 49 |      * @param[in] authAlgo - Authentication Algorithm | 
 | 50 |      * @param[in] intAlgo - Integrity Algorithm | 
 | 51 |      * @param[in] cryptAlgo - Confidentiality Algorithm | 
 | 52 |      * | 
 | 53 |      * @return session handle on success and nullptr on failure | 
 | 54 |      * | 
 | 55 |      */ | 
| Vernon Mauery | ae1fda4 | 2018-10-15 12:55:34 -0700 | [diff] [blame] | 56 |     std::shared_ptr<Session> | 
 | 57 |         startSession(SessionID remoteConsoleSessID, Privilege priv, | 
 | 58 |                      cipher::rakp_auth::Algorithms authAlgo, | 
 | 59 |                      cipher::integrity::Algorithms intAlgo, | 
 | 60 |                      cipher::crypt::Algorithms cryptAlgo); | 
| Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 61 |  | 
| Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 62 |     /** | 
 | 63 |      * @brief Stop IPMI Session | 
 | 64 |      * | 
 | 65 |      * @param[in] bmcSessionID - BMC Session ID | 
 | 66 |      * | 
 | 67 |      * @return true on success and failure if session ID is invalid | 
 | 68 |      * | 
 | 69 |      */ | 
 | 70 |     bool stopSession(SessionID bmcSessionID); | 
| Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 71 |  | 
| Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 72 |     /** | 
 | 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 |      */ | 
| Vernon Mauery | ae1fda4 | 2018-10-15 12:55:34 -0700 | [diff] [blame] | 82 |     std::shared_ptr<Session> | 
| Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 83 |         getSession(SessionID sessionID, | 
 | 84 |                    RetrieveOption option = RetrieveOption::BMC_SESSION_ID); | 
| Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 85 |  | 
| Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 86 |   private: | 
 | 87 |     /** | 
 | 88 |      * @brief Session Manager keeps the session objects as a sorted | 
 | 89 |      *        associative container with Session ID as the unique key | 
 | 90 |      */ | 
 | 91 |     SessionMap sessionsMap; | 
| Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 92 |  | 
| Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 93 |     /** | 
 | 94 |      * @brief Clean Session Stale Entries | 
 | 95 |      * | 
 | 96 |      *  Removes the inactive sessions entries from the Session Map | 
 | 97 |      */ | 
 | 98 |     void cleanStaleEntries(); | 
| Tom Joseph | 3e61aa0 | 2016-08-08 08:42:39 -0500 | [diff] [blame] | 99 | }; | 
 | 100 |  | 
 | 101 | } // namespace session |