blob: 4a42bf4099ffa4d2ea310ee262b2b16af9912743 [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);
Deepak Kodihallibc669f12019-11-28 08:52:07 -060088};
Sampa Misrab37be312019-07-03 02:26:41 -050089
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050090} // namespace bios
91
Sampa Misra032bd502019-03-06 05:03:22 -060092namespace 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 */
105void epochToBCDTime(uint64_t timeSec, uint8_t& seconds, uint8_t& minutes,
106 uint8_t& hours, uint8_t& day, uint8_t& month,
107 uint16_t& year);
Xiaochao Ma60227a02019-12-04 09:00:12 +0800108
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 */
119std::time_t timeToEpoch(uint8_t seconds, uint8_t minutes, uint8_t hours,
120 uint8_t day, uint8_t month, uint16_t year);
Sampa Misra032bd502019-03-06 05:03:22 -0600121} // namespace utils
122
123} // namespace responder
124} // namespace pldm