| /* |
| * Copyright (c) 2018-present Facebook. All Rights Reserved. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #include <ipmid/api.h> |
| #include <stdbool.h> |
| #include <stdio.h> |
| #include <sys/stat.h> |
| |
| #include <appcommands.hpp> |
| #include <ipmid/api.hpp> |
| #include <ipmid/utils.hpp> |
| #include <nlohmann/json.hpp> |
| #include <phosphor-logging/lg2.hpp> |
| #include <phosphor-logging/log.hpp> |
| #include <sdbusplus/asio/connection.hpp> |
| #include <sdbusplus/asio/property.hpp> |
| |
| #include <fstream> |
| #include <iomanip> |
| #include <iostream> |
| #include <sstream> |
| |
| namespace ipmi |
| { |
| |
| static constexpr bool DEBUG = false; |
| |
| static constexpr auto JSON_POST_DATA_FILE = |
| "/usr/share/lcd-debug/post_desc.json"; |
| static constexpr auto JSON_GPIO_DATA_FILE = |
| "/usr/share/lcd-debug/gpio_desc.json"; |
| static constexpr auto JSON_SENSOR_NAMES_FILE = |
| "/usr/share/lcd-debug/cri_sensors.json"; |
| |
| static constexpr auto ETH_INTF_NAME = "eth0"; |
| |
| #define ESCAPE "\x1B" |
| #define ESC_BAT ESCAPE "B" |
| #define ESC_MCU_BL_VER ESCAPE "U" |
| #define ESC_MCU_RUN_VER ESCAPE "R" |
| #define ESC_ALT ESCAPE "[5;7m" |
| #define ESC_RST ESCAPE "[m" |
| |
| static constexpr char LINE_DELIMITER = '\x1F'; |
| |
| static constexpr size_t FRAME_BUFF_SIZE = 4096; |
| static constexpr size_t FRAME_PAGE_BUF_SIZE = 256; |
| |
| #define FRU_ALL 0 |
| |
| static constexpr auto DEBUG_GPIO_KEY = "GpioDesc"; |
| static constexpr auto GPIO_ARRAY_SIZE = 4; |
| static constexpr auto GPIO_PIN_INDEX = 0; |
| static constexpr auto GPIO_LEVEL_INDEX = 1; |
| static constexpr auto GPIO_DEF_INDEX = 2; |
| static constexpr auto GPIO_DESC_INDEX = 3; |
| |
| static constexpr size_t BMC_POSITION = 0; |
| |
| static constexpr uint8_t meAddress = 1; |
| static constexpr uint8_t lun = 0; |
| |
| using IpmbMethodType = |
| std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>; |
| |
| struct frame |
| { |
| char title[32]; |
| size_t max_size; |
| size_t max_page; |
| char* buf; |
| size_t idx_head, idx_tail; |
| size_t line_per_page; |
| size_t line_width; |
| size_t lines, pages; |
| uint8_t esc_sts; |
| bool overwrite; |
| time_t mtime; |
| |
| frame() : buf(nullptr), pages(0), mtime(0) {} |
| |
| void init(size_t size = FRAME_BUFF_SIZE); |
| void append(const std::string& str, size_t indent = 0); |
| int getPage(size_t page, char* page_buf, size_t page_buf_size); |
| bool isFull() const; |
| bool isEscSeq(char chr); |
| |
| private: |
| auto parse(const std::string& input, size_t indent) -> std::string; |
| }; |
| |
| frame frame_info; |
| frame frame_sel; |
| frame frame_snr; |
| frame frame_postcode; |
| |
| enum class panel : uint8_t |
| { |
| NONE = 0, |
| MAIN = 1, |
| BOOT_ORDER = 2, |
| POWER_POLICY = 3, |
| }; |
| |
| struct ctrl_panel |
| { |
| panel parent; |
| size_t item_num; |
| std::array<std::string, 8> item_str; |
| panel (*select)(size_t item); |
| }; |
| |
| static panel panel_main(size_t item); |
| static panel panel_boot_order(size_t item); |
| static panel panel_power_policy(size_t item); |
| |
| static ctrl_panel panels[] = { |
| {/* dummy entry for making other to 1-based */}, |
| { |
| .parent = panel::MAIN, |
| .item_num = 2, |
| .item_str = |
| { |
| "User Setting", |
| ">Boot Order", |
| ">Power Policy", |
| }, |
| .select = panel_main, |
| }, |
| { |
| .parent = panel::MAIN, |
| .item_num = 0, |
| .item_str = |
| { |
| "Boot Order", |
| }, |
| .select = panel_boot_order, |
| }, |
| { |
| .parent = panel::MAIN, |
| .item_num = 0, |
| .item_str = |
| { |
| "Power Policy", |
| }, |
| .select = panel_power_policy, |
| }, |
| }; |
| |
| } // end of namespace ipmi |