xref: /openbmc/pldm/libpldmresponder/bios.hpp (revision 83e068ad)
1 #pragma once
2 
3 #include "bios_config.hpp"
4 #include "bios_table.hpp"
5 #include "common/instance_id.hpp"
6 #include "platform_config.hpp"
7 #include "pldmd/handler.hpp"
8 #include "requester/handler.hpp"
9 
10 #include <libpldm/bios.h>
11 #include <libpldm/bios_table.h>
12 #include <stdint.h>
13 
14 #include <ctime>
15 #include <functional>
16 #include <map>
17 #include <vector>
18 
19 namespace pldm
20 {
21 
22 namespace responder
23 {
24 
25 namespace bios
26 {
27 
28 class Handler : public CmdHandler
29 {
30   public:
31     /** @brief Constructor
32      *
33      *  @param[in] fd - socket descriptor to communicate to host
34      *  @param[in] eid - MCTP EID of host firmware
35      *  @param[in] instanceIdDb - pointer to an InstanceIdDb object
36      *  @param[in] handler - PLDM request handler
37      *  @param[in] platformConfigHandler - pointer to platform config object
38      */
39     Handler(int fd, uint8_t eid, pldm::InstanceIdDb* instanceIdDb,
40             pldm::requester::Handler<pldm::requester::Request>* handler,
41             pldm::responder::platform_config::Handler* platformConfigHandler);
42 
43     /** @brief Handler for GetDateTime
44      *
45      *  @param[in] request - Request message payload
46      *  @return Response - PLDM Response message
47      */
48     Response getDateTime(const pldm_msg* request, size_t payloadLength);
49 
50     /** @brief Handler for GetBIOSTable
51      *
52      *  @param[in] request - Request message
53      *  @param[in] payload_length - Request message payload length
54      *  @return Response - PLDM Response message
55      */
56     Response getBIOSTable(const pldm_msg* request, size_t payloadLength);
57 
58     /** @brief Handler for SetBIOSTable
59      *
60      *  @param[in] request - Request message
61      *  @param[in] payload_length - Request message payload length
62      *  @return Response - PLDM Response message
63      */
64     Response setBIOSTable(const pldm_msg* request, size_t payloadLength);
65 
66     /** @brief Handler for GetBIOSAttributeCurrentValueByHandle
67      *
68      *  @param[in] request - Request message
69      *  @param[in] payloadLength - Request message payload length
70      *  @return Response - PLDM Response message
71      */
72     Response getBIOSAttributeCurrentValueByHandle(const pldm_msg* request,
73                                                   size_t payloadLength);
74 
75     /** @brief Handler for SetDateTime
76      *
77      *  @param[in] request - Request message payload
78      *  @param[in] payloadLength - Request message payload length
79      *  @return Response - PLDM Response message
80      */
81     Response setDateTime(const pldm_msg* request, size_t payloadLength);
82 
83     /** @brief Handler for setBIOSAttributeCurrentValue
84      *
85      *  @param[in] request - Request message
86      *  @param[in] payloadLength - Request message payload length
87      *  @return Response - PLDM Response message
88      */
89     Response setBIOSAttributeCurrentValue(const pldm_msg* request,
90                                           size_t payloadLength);
91 
92   private:
93     BIOSConfig biosConfig;
94 };
95 
96 } // namespace bios
97 
98 namespace utils
99 {
100 
101 /** @brief Convert epoch time to BCD time
102  *
103  *  @param[in] timeSec - Time got from epoch time in seconds
104  *  @param[out] seconds - number of seconds in BCD
105  *  @param[out] minutes - number of minutes in BCD
106  *  @param[out] hours - number of hours in BCD
107  *  @param[out] day - day of the month in BCD
108  *  @param[out] month - month number in BCD
109  *  @param[out] year - year number in BCD
110  */
111 void epochToBCDTime(uint64_t timeSec, uint8_t& seconds, uint8_t& minutes,
112                     uint8_t& hours, uint8_t& day, uint8_t& month,
113                     uint16_t& year);
114 
115 /** @brief Convert dec time to epoch time
116  *
117  *  @param[in] seconds - number of seconds in dec
118  *  @param[in] minutes - number of minutes in dec
119  *  @param[in] hours - number of hours in dec
120  *  @param[in] day - day of the month in dec
121  *  @param[in] month - month number in dec
122  *  @param[in] year - year number in dec
123  *  @return time - epoch time
124  */
125 std::time_t timeToEpoch(uint8_t seconds, uint8_t minutes, uint8_t hours,
126                         uint8_t day, uint8_t month, uint16_t year);
127 } // namespace utils
128 
129 } // namespace responder
130 } // namespace pldm
131