xref: /openbmc/pldm/libpldmresponder/bios.hpp (revision d9fb152669375b8aabf8e4c51644d194d357b16c)
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 <functional>
12 #include <map>
13 #include <vector>
14 
15 #include "libpldm/bios.h"
16 #include "libpldm/bios_table.h"
17 
18 namespace pldm
19 {
20 
21 using AttributeHandle = uint16_t;
22 using StringHandle = uint16_t;
23 using PossibleValuesByHandle = std::vector<StringHandle>;
24 
25 namespace responder
26 {
27 
28 namespace bios
29 {
30 
31 using AttrTableEntryHandler =
32     std::function<void(const struct pldm_bios_attr_table_entry*)>;
33 
34 void traverseBIOSAttrTable(const bios::Table& BIOSAttrTable,
35                            AttrTableEntryHandler handler);
36 
37 namespace internal
38 {
39 
40 /** @brief Constructs all the BIOS Tables
41  *
42  *  @param[in] request - Request message
43  *  @param[in] payload_length - Request message payload length
44  *  @param[in] biosJsonDir - path to fetch the BIOS json files
45  *  @param[in] biosTablePath - path where the BIOS tables will be persisted
46  */
47 Response buildBIOSTables(const pldm_msg* request, size_t payloadLength,
48                          const char* biosJsonDir, const char* biosTablePath);
49 } // namespace internal
50 
51 class Handler : public CmdHandler
52 {
53   public:
54     Handler();
55 
56     /** @brief Handler for GetDateTime
57      *
58      *  @param[in] request - Request message payload
59      *  @param[return] Response - PLDM Response message
60      */
61     Response getDateTime(const pldm_msg* request, size_t payloadLength);
62 
63     /** @brief Handler for GetBIOSTable
64      *
65      *  @param[in] request - Request message
66      *  @param[in] payload_length - Request message payload length
67      *  @param[return] Response - PLDM Response message
68      */
69     Response getBIOSTable(const pldm_msg* request, size_t payloadLength);
70 };
71 
72 } // namespace bios
73 
74 namespace utils
75 {
76 
77 /** @brief Convert epoch time to BCD time
78  *
79  *  @param[in] timeSec - Time got from epoch time in seconds
80  *  @param[out] seconds - number of seconds in BCD
81  *  @param[out] minutes - number of minutes in BCD
82  *  @param[out] hours - number of hours in BCD
83  *  @param[out] day - day of the month in BCD
84  *  @param[out] month - month number in BCD
85  *  @param[out] year - year number in BCD
86  */
87 void epochToBCDTime(uint64_t timeSec, uint8_t& seconds, uint8_t& minutes,
88                     uint8_t& hours, uint8_t& day, uint8_t& month,
89                     uint16_t& year);
90 } // namespace utils
91 
92 } // namespace responder
93 } // namespace pldm
94