Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018-present Facebook. All Rights Reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Patrick Williams | f863a18 | 2022-06-16 16:17:28 -0500 | [diff] [blame] | 17 | #include <ipmid/api.h> |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 18 | #include <stdbool.h> |
| 19 | #include <stdio.h> |
| 20 | #include <sys/stat.h> |
| 21 | |
| 22 | #include <appcommands.hpp> |
| 23 | #include <ipmid/api.hpp> |
Patrick Williams | 2405ae9 | 2023-05-10 07:50:09 -0500 | [diff] [blame] | 24 | #include <ipmid/utils.hpp> |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 25 | #include <nlohmann/json.hpp> |
Karthikeyan Pasupathi | e1ff81f | 2022-11-21 17:54:46 +0530 | [diff] [blame] | 26 | #include <phosphor-logging/lg2.hpp> |
Patrick Williams | 2405ae9 | 2023-05-10 07:50:09 -0500 | [diff] [blame] | 27 | #include <phosphor-logging/log.hpp> |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 28 | #include <sdbusplus/asio/connection.hpp> |
Karthikeyan Pasupathi | 39836ff | 2022-01-17 12:20:06 +0530 | [diff] [blame] | 29 | #include <sdbusplus/asio/property.hpp> |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 30 | |
| 31 | #include <fstream> |
| 32 | #include <iomanip> |
| 33 | #include <iostream> |
| 34 | #include <sstream> |
| 35 | |
| 36 | namespace ipmi |
| 37 | { |
| 38 | |
Patrick Williams | 13ce379 | 2024-08-27 13:03:46 -0400 | [diff] [blame^] | 39 | static constexpr bool DEBUG = false; |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 40 | |
Patrick Williams | 13ce379 | 2024-08-27 13:03:46 -0400 | [diff] [blame^] | 41 | static constexpr auto JSON_POST_DATA_FILE = |
| 42 | "/usr/share/lcd-debug/post_desc.json"; |
| 43 | static constexpr auto JSON_GPIO_DATA_FILE = |
| 44 | "/usr/share/lcd-debug/gpio_desc.json"; |
| 45 | static constexpr auto JSON_SENSOR_NAMES_FILE = |
| 46 | "/usr/share/lcd-debug/cri_sensors.json"; |
| 47 | |
| 48 | static constexpr auto ETH_INTF_NAME = "eth0"; |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 49 | |
| 50 | #define ESCAPE "\x1B" |
| 51 | #define ESC_BAT ESCAPE "B" |
| 52 | #define ESC_MCU_BL_VER ESCAPE "U" |
| 53 | #define ESC_MCU_RUN_VER ESCAPE "R" |
| 54 | #define ESC_ALT ESCAPE "[5;7m" |
| 55 | #define ESC_RST ESCAPE "[m" |
| 56 | |
Patrick Williams | 13ce379 | 2024-08-27 13:03:46 -0400 | [diff] [blame^] | 57 | static constexpr char LINE_DELIMITER = '\x1F'; |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 58 | |
Patrick Williams | 13ce379 | 2024-08-27 13:03:46 -0400 | [diff] [blame^] | 59 | static constexpr size_t FRAME_BUFF_SIZE = 4096; |
| 60 | static constexpr size_t FRAME_PAGE_BUF_SIZE = 256; |
| 61 | |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 62 | #define FRU_ALL 0 |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 63 | |
Patrick Williams | 13ce379 | 2024-08-27 13:03:46 -0400 | [diff] [blame^] | 64 | static constexpr auto DEBUG_GPIO_KEY = "GpioDesc"; |
| 65 | static constexpr auto GPIO_ARRAY_SIZE = 4; |
| 66 | static constexpr auto GPIO_PIN_INDEX = 0; |
| 67 | static constexpr auto GPIO_LEVEL_INDEX = 1; |
| 68 | static constexpr auto GPIO_DEF_INDEX = 2; |
| 69 | static constexpr auto GPIO_DESC_INDEX = 3; |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 70 | |
Patrick Williams | 13ce379 | 2024-08-27 13:03:46 -0400 | [diff] [blame^] | 71 | static constexpr size_t BMC_POSITION = 0; |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 72 | |
Patrick Williams | 13ce379 | 2024-08-27 13:03:46 -0400 | [diff] [blame^] | 73 | static constexpr uint8_t meAddress = 1; |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 74 | static constexpr uint8_t lun = 0; |
| 75 | |
| 76 | using IpmbMethodType = |
| 77 | std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>; |
| 78 | |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 79 | struct frame |
| 80 | { |
| 81 | char title[32]; |
| 82 | size_t max_size; |
| 83 | size_t max_page; |
| 84 | char* buf; |
Patrick Williams | 13ce379 | 2024-08-27 13:03:46 -0400 | [diff] [blame^] | 85 | size_t idx_head, idx_tail; |
| 86 | size_t line_per_page; |
| 87 | size_t line_width; |
| 88 | size_t lines, pages; |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 89 | uint8_t esc_sts; |
Patrick Williams | 13ce379 | 2024-08-27 13:03:46 -0400 | [diff] [blame^] | 90 | bool overwrite; |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 91 | time_t mtime; |
Patrick Williams | 13ce379 | 2024-08-27 13:03:46 -0400 | [diff] [blame^] | 92 | |
| 93 | frame() : buf(nullptr), pages(0), mtime(0) {} |
| 94 | |
| 95 | void init(size_t size = FRAME_BUFF_SIZE); |
| 96 | void append(const std::string& str, size_t indent = 0); |
| 97 | int getPage(size_t page, char* page_buf, size_t page_buf_size); |
| 98 | bool isFull() const; |
| 99 | bool isEscSeq(char chr); |
| 100 | |
| 101 | private: |
| 102 | auto parse(const std::string& input, size_t indent) -> std::string; |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 103 | }; |
| 104 | |
Patrick Williams | 13ce379 | 2024-08-27 13:03:46 -0400 | [diff] [blame^] | 105 | frame frame_info; |
| 106 | frame frame_sel; |
| 107 | frame frame_snr; |
| 108 | frame frame_postcode; |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 109 | |
Patrick Williams | a758d0a | 2024-08-27 08:35:55 -0400 | [diff] [blame] | 110 | enum class panel : uint8_t |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 111 | { |
Patrick Williams | a758d0a | 2024-08-27 08:35:55 -0400 | [diff] [blame] | 112 | NONE = 0, |
| 113 | MAIN = 1, |
| 114 | BOOT_ORDER = 2, |
| 115 | POWER_POLICY = 3, |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | struct ctrl_panel |
| 119 | { |
Patrick Williams | a758d0a | 2024-08-27 08:35:55 -0400 | [diff] [blame] | 120 | panel parent; |
| 121 | size_t item_num; |
| 122 | std::array<std::string, 8> item_str; |
| 123 | panel (*select)(size_t item); |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 124 | }; |
| 125 | |
Patrick Williams | a758d0a | 2024-08-27 08:35:55 -0400 | [diff] [blame] | 126 | static panel panel_main(size_t item); |
| 127 | static panel panel_boot_order(size_t item); |
| 128 | static panel panel_power_policy(size_t item); |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 129 | |
Patrick Williams | a758d0a | 2024-08-27 08:35:55 -0400 | [diff] [blame] | 130 | static ctrl_panel panels[] = { |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 131 | {/* dummy entry for making other to 1-based */}, |
| 132 | { |
Patrick Williams | a758d0a | 2024-08-27 08:35:55 -0400 | [diff] [blame] | 133 | .parent = panel::MAIN, |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 134 | .item_num = 2, |
| 135 | .item_str = |
| 136 | { |
| 137 | "User Setting", |
| 138 | ">Boot Order", |
| 139 | ">Power Policy", |
| 140 | }, |
| 141 | .select = panel_main, |
| 142 | }, |
| 143 | { |
Patrick Williams | a758d0a | 2024-08-27 08:35:55 -0400 | [diff] [blame] | 144 | .parent = panel::MAIN, |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 145 | .item_num = 0, |
| 146 | .item_str = |
| 147 | { |
| 148 | "Boot Order", |
| 149 | }, |
| 150 | .select = panel_boot_order, |
| 151 | }, |
| 152 | { |
Patrick Williams | a758d0a | 2024-08-27 08:35:55 -0400 | [diff] [blame] | 153 | .parent = panel::MAIN, |
Karthikeyan Pasupathi | 813f293 | 2022-04-06 14:10:48 +0530 | [diff] [blame] | 154 | .item_num = 0, |
| 155 | .item_str = |
| 156 | { |
| 157 | "Power Policy", |
| 158 | }, |
| 159 | .select = panel_power_policy, |
| 160 | }, |
| 161 | }; |
| 162 | |
| 163 | } // end of namespace ipmi |