blob: d023ce9415ed81de6033fa17a6e5e68a0497dbfc [file] [log] [blame]
Sampa Misra032bd502019-03-06 05:03:22 -06001#pragma once
2
Sampa Misrab37be312019-07-03 02:26:41 -05003#include "config.h"
4
5#include "bios_parser.hpp"
6#include "bios_table.hpp"
Deepak Kodihallibc669f12019-11-28 08:52:07 -06007#include "handler.hpp"
Sampa Misrab37be312019-07-03 02:26:41 -05008
Sampa Misra032bd502019-03-06 05:03:22 -06009#include <stdint.h>
10
Xiaochao Ma60227a02019-12-04 09:00:12 +080011#include <ctime>
John Wang02700402019-10-06 16:34:29 +080012#include <functional>
Sampa Misrab37be312019-07-03 02:26:41 -050013#include <map>
vkaverapa6575b82019-04-03 05:33:52 -050014#include <vector>
15
Sampa Misra032bd502019-03-06 05:03:22 -060016#include "libpldm/bios.h"
John Wang02700402019-10-06 16:34:29 +080017#include "libpldm/bios_table.h"
Sampa Misra032bd502019-03-06 05:03:22 -060018
19namespace pldm
20{
21
Sampa Misrab37be312019-07-03 02:26:41 -050022using AttributeHandle = uint16_t;
23using StringHandle = uint16_t;
24using PossibleValuesByHandle = std::vector<StringHandle>;
vkaverapa6575b82019-04-03 05:33:52 -050025
Sampa Misra032bd502019-03-06 05:03:22 -060026namespace responder
27{
28
Deepak Kodihallibc669f12019-11-28 08:52:07 -060029namespace bios
30{
31
John Wang02700402019-10-06 16:34:29 +080032using AttrTableEntryHandler =
33 std::function<void(const struct pldm_bios_attr_table_entry*)>;
34
35void traverseBIOSAttrTable(const bios::Table& BIOSAttrTable,
36 AttrTableEntryHandler handler);
37
Sampa Misrab37be312019-07-03 02:26:41 -050038namespace 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 */
48Response buildBIOSTables(const pldm_msg* request, size_t payloadLength,
49 const char* biosJsonDir, const char* biosTablePath);
Deepak Kodihallibc669f12019-11-28 08:52:07 -060050} // namespace internal
51
52class Handler : public CmdHandler
53{
54 public:
Deepak Kodihallid9fb1522019-11-28 10:06:34 -060055 Handler();
Deepak Kodihallibc669f12019-11-28 08:52:07 -060056
57 /** @brief Handler for GetDateTime
58 *
59 * @param[in] request - Request message payload
Xiaochao Ma60227a02019-12-04 09:00:12 +080060 * @return Response - PLDM Response message
Deepak Kodihallibc669f12019-11-28 08:52:07 -060061 */
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
Xiaochao Ma60227a02019-12-04 09:00:12 +080068 * @return Response - PLDM Response message
Deepak Kodihallibc669f12019-11-28 08:52:07 -060069 */
70 Response getBIOSTable(const pldm_msg* request, size_t payloadLength);
John Wang8721ed62019-12-05 14:44:43 +080071
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);
Xiaochao Ma60227a02019-12-04 09:00:12 +080080
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);
John Wang42174882019-12-20 14:56:59 +080088
89 /** @brief Handler for setBIOSAttributeCurrentValue
90 *
91 * @param[in] request - Request message
92 * @param[in] payloadLength - Request message payload length
93 * @return Response - PLDM Response message
94 */
95 Response setBIOSAttributeCurrentValue(const pldm_msg* request,
96 size_t payloadLength);
Deepak Kodihallibc669f12019-11-28 08:52:07 -060097};
Sampa Misrab37be312019-07-03 02:26:41 -050098
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050099} // namespace bios
100
Sampa Misra032bd502019-03-06 05:03:22 -0600101namespace utils
102{
103
104/** @brief Convert epoch time to BCD time
105 *
106 * @param[in] timeSec - Time got from epoch time in seconds
107 * @param[out] seconds - number of seconds in BCD
108 * @param[out] minutes - number of minutes in BCD
109 * @param[out] hours - number of hours in BCD
110 * @param[out] day - day of the month in BCD
111 * @param[out] month - month number in BCD
112 * @param[out] year - year number in BCD
113 */
114void epochToBCDTime(uint64_t timeSec, uint8_t& seconds, uint8_t& minutes,
115 uint8_t& hours, uint8_t& day, uint8_t& month,
116 uint16_t& year);
Xiaochao Ma60227a02019-12-04 09:00:12 +0800117
118/** @brief Convert dec time to epoch time
119 *
120 * @param[in] seconds - number of seconds in dec
121 * @param[in] minutes - number of minutes in dec
122 * @param[in] hours - number of hours in dec
123 * @param[in] day - day of the month in dec
124 * @param[in] month - month number in dec
125 * @param[in] year - year number in dec
126 * @return time - epoch time
127 */
128std::time_t timeToEpoch(uint8_t seconds, uint8_t minutes, uint8_t hours,
129 uint8_t day, uint8_t month, uint16_t year);
Sampa Misra032bd502019-03-06 05:03:22 -0600130} // namespace utils
131
132} // namespace responder
133} // namespace pldm