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