Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
| 5 | #include "bios_parser.hpp" |
| 6 | #include "bios_table.hpp" |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 7 | #include "handler.hpp" |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 8 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 11 | #include <ctime> |
John Wang | 0270040 | 2019-10-06 16:34:29 +0800 | [diff] [blame] | 12 | #include <functional> |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 13 | #include <map> |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 16 | #include "libpldm/bios.h" |
John Wang | 0270040 | 2019-10-06 16:34:29 +0800 | [diff] [blame] | 17 | #include "libpldm/bios_table.h" |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 18 | |
| 19 | namespace pldm |
| 20 | { |
| 21 | |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 22 | using AttributeHandle = uint16_t; |
| 23 | using StringHandle = uint16_t; |
| 24 | using PossibleValuesByHandle = std::vector<StringHandle>; |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 25 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 26 | namespace responder |
| 27 | { |
| 28 | |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 29 | namespace bios |
| 30 | { |
| 31 | |
John Wang | 0270040 | 2019-10-06 16:34:29 +0800 | [diff] [blame] | 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 | |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 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); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 50 | } // namespace internal |
| 51 | |
| 52 | class Handler : public CmdHandler |
| 53 | { |
| 54 | public: |
Deepak Kodihalli | d9fb152 | 2019-11-28 10:06:34 -0600 | [diff] [blame] | 55 | Handler(); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 56 | |
| 57 | /** @brief Handler for GetDateTime |
| 58 | * |
| 59 | * @param[in] request - Request message payload |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 60 | * @return Response - PLDM Response message |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 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 |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 68 | * @return Response - PLDM Response message |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 69 | */ |
| 70 | Response getBIOSTable(const pldm_msg* request, size_t payloadLength); |
John Wang | 8721ed6 | 2019-12-05 14:44:43 +0800 | [diff] [blame] | 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); |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 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); |
John Wang | 4217488 | 2019-12-20 14:56:59 +0800 | [diff] [blame] | 88 | |
| 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 Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 97 | }; |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 98 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 99 | } // namespace bios |
| 100 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 101 | namespace 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 | */ |
| 114 | void 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 Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 117 | |
| 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 | */ |
| 128 | std::time_t timeToEpoch(uint8_t seconds, uint8_t minutes, uint8_t hours, |
| 129 | uint8_t day, uint8_t month, uint16_t year); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 130 | } // namespace utils |
| 131 | |
| 132 | } // namespace responder |
| 133 | } // namespace pldm |