xref: /openbmc/pldm/libpldmresponder/bios.hpp (revision 60227a0be03d069dc374ad6f7ffbf2d4bd8d52dd)
1 #pragma once
2 
3 #include "config.h"
4 
5 #include "bios_parser.hpp"
6 #include "bios_table.hpp"
7 #include "handler.hpp"
8 
9 #include <stdint.h>
10 
11 #include <ctime>
12 #include <functional>
13 #include <map>
14 #include <vector>
15 
16 #include "libpldm/bios.h"
17 #include "libpldm/bios_table.h"
18 
19 namespace pldm
20 {
21 
22 using AttributeHandle = uint16_t;
23 using StringHandle = uint16_t;
24 using PossibleValuesByHandle = std::vector<StringHandle>;
25 
26 namespace responder
27 {
28 
29 namespace bios
30 {
31 
32 using AttrTableEntryHandler =
33     std::function<void(const struct pldm_bios_attr_table_entry*)>;
34 
35 void traverseBIOSAttrTable(const bios::Table& BIOSAttrTable,
36                            AttrTableEntryHandler handler);
37 
38 namespace internal
39 {
40 
41 /** @brief Constructs all the BIOS Tables
42  *
43  *  @param[in] request - Request message
44  *  @param[in] payload_length - Request message payload length
45  *  @param[in] biosJsonDir - path to fetch the BIOS json files
46  *  @param[in] biosTablePath - path where the BIOS tables will be persisted
47  */
48 Response buildBIOSTables(const pldm_msg* request, size_t payloadLength,
49                          const char* biosJsonDir, const char* biosTablePath);
50 } // namespace internal
51 
52 class Handler : public CmdHandler
53 {
54   public:
55     Handler();
56 
57     /** @brief Handler for GetDateTime
58      *
59      *  @param[in] request - Request message payload
60      *  @return Response - PLDM Response message
61      */
62     Response getDateTime(const pldm_msg* request, size_t payloadLength);
63 
64     /** @brief Handler for GetBIOSTable
65      *
66      *  @param[in] request - Request message
67      *  @param[in] payload_length - Request message payload length
68      *  @return Response - PLDM Response message
69      */
70     Response getBIOSTable(const pldm_msg* request, size_t payloadLength);
71 
72     /** @brief Handler for GetBIOSAttributeCurrentValueByHandle
73      *
74      *  @param[in] request - Request message
75      *  @param[in] payloadLength - Request message payload length
76      *  @return Response - PLDM Response message
77      */
78     Response getBIOSAttributeCurrentValueByHandle(const pldm_msg* request,
79                                                   size_t payloadLength);
80 
81     /** @brief Handler for SetDateTime
82      *
83      *  @param[in] request - Request message payload
84      *  @param[in] payloadLength - Request message payload length
85      *  @return Response - PLDM Response message
86      */
87     Response setDateTime(const pldm_msg* request, size_t payloadLength);
88 };
89 
90 } // namespace bios
91 
92 namespace utils
93 {
94 
95 /** @brief Convert epoch time to BCD time
96  *
97  *  @param[in] timeSec - Time got from epoch time in seconds
98  *  @param[out] seconds - number of seconds in BCD
99  *  @param[out] minutes - number of minutes in BCD
100  *  @param[out] hours - number of hours in BCD
101  *  @param[out] day - day of the month in BCD
102  *  @param[out] month - month number in BCD
103  *  @param[out] year - year number in BCD
104  */
105 void epochToBCDTime(uint64_t timeSec, uint8_t& seconds, uint8_t& minutes,
106                     uint8_t& hours, uint8_t& day, uint8_t& month,
107                     uint16_t& year);
108 
109 /** @brief Convert dec time to epoch time
110  *
111  *  @param[in] seconds - number of seconds in dec
112  *  @param[in] minutes - number of minutes in dec
113  *  @param[in] hours - number of hours in dec
114  *  @param[in] day - day of the month in dec
115  *  @param[in] month - month number in dec
116  *  @param[in] year - year number in dec
117  *  @return time - epoch time
118  */
119 std::time_t timeToEpoch(uint8_t seconds, uint8_t minutes, uint8_t hours,
120                         uint8_t day, uint8_t month, uint16_t year);
121 } // namespace utils
122 
123 } // namespace responder
124 } // namespace pldm
125