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); |
Deepak Kodihalli | bc669f1 | 2019-11-28 08:52:07 -0600 | [diff] [blame] | 88 | }; |
Sampa Misra | b37be31 | 2019-07-03 02:26:41 -0500 | [diff] [blame] | 89 | |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 90 | } // namespace bios |
| 91 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 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); |
Xiaochao Ma | 60227a0 | 2019-12-04 09:00:12 +0800 | [diff] [blame] | 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); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 121 | } // namespace utils |
| 122 | |
| 123 | } // namespace responder |
| 124 | } // namespace pldm |