blob: 13441504af55f1ab1199b04d7da3c050f7ab2b8b [file] [log] [blame]
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +05301/*
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 Williamsf863a182022-06-16 16:17:28 -050017#include <ipmid/api.h>
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053018#include <stdbool.h>
19#include <stdio.h>
20#include <sys/stat.h>
21
22#include <appcommands.hpp>
23#include <ipmid/api.hpp>
Patrick Williams2405ae92023-05-10 07:50:09 -050024#include <ipmid/utils.hpp>
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053025#include <nlohmann/json.hpp>
Karthikeyan Pasupathie1ff81f2022-11-21 17:54:46 +053026#include <phosphor-logging/lg2.hpp>
Patrick Williams2405ae92023-05-10 07:50:09 -050027#include <phosphor-logging/log.hpp>
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053028#include <sdbusplus/asio/connection.hpp>
Karthikeyan Pasupathi39836ff2022-01-17 12:20:06 +053029#include <sdbusplus/asio/property.hpp>
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053030
31#include <fstream>
32#include <iomanip>
33#include <iostream>
34#include <sstream>
35
36namespace ipmi
37{
38
Patrick Williams13ce3792024-08-27 13:03:46 -040039static constexpr bool DEBUG = false;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053040
Patrick Williams13ce3792024-08-27 13:03:46 -040041static constexpr auto JSON_POST_DATA_FILE =
42 "/usr/share/lcd-debug/post_desc.json";
43static constexpr auto JSON_GPIO_DATA_FILE =
44 "/usr/share/lcd-debug/gpio_desc.json";
45static constexpr auto JSON_SENSOR_NAMES_FILE =
46 "/usr/share/lcd-debug/cri_sensors.json";
47
48static constexpr auto ETH_INTF_NAME = "eth0";
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053049
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 Williams13ce3792024-08-27 13:03:46 -040057static constexpr char LINE_DELIMITER = '\x1F';
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053058
Patrick Williams13ce3792024-08-27 13:03:46 -040059static constexpr size_t FRAME_BUFF_SIZE = 4096;
60static constexpr size_t FRAME_PAGE_BUF_SIZE = 256;
61
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053062#define FRU_ALL 0
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053063
Patrick Williams13ce3792024-08-27 13:03:46 -040064static constexpr auto DEBUG_GPIO_KEY = "GpioDesc";
65static constexpr auto GPIO_ARRAY_SIZE = 4;
66static constexpr auto GPIO_PIN_INDEX = 0;
67static constexpr auto GPIO_LEVEL_INDEX = 1;
68static constexpr auto GPIO_DEF_INDEX = 2;
69static constexpr auto GPIO_DESC_INDEX = 3;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053070
Patrick Williams13ce3792024-08-27 13:03:46 -040071static constexpr size_t BMC_POSITION = 0;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053072
Patrick Williams13ce3792024-08-27 13:03:46 -040073static constexpr uint8_t meAddress = 1;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053074static constexpr uint8_t lun = 0;
75
76using IpmbMethodType =
77 std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>;
78
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053079struct frame
80{
81 char title[32];
82 size_t max_size;
83 size_t max_page;
84 char* buf;
Patrick Williams13ce3792024-08-27 13:03:46 -040085 size_t idx_head, idx_tail;
86 size_t line_per_page;
87 size_t line_width;
88 size_t lines, pages;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053089 uint8_t esc_sts;
Patrick Williams13ce3792024-08-27 13:03:46 -040090 bool overwrite;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +053091 time_t mtime;
Patrick Williams13ce3792024-08-27 13:03:46 -040092
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 Pasupathi813f2932022-04-06 14:10:48 +0530103};
104
Patrick Williams13ce3792024-08-27 13:03:46 -0400105frame frame_info;
106frame frame_sel;
107frame frame_snr;
108frame frame_postcode;
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530109
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400110enum class panel : uint8_t
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530111{
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400112 NONE = 0,
113 MAIN = 1,
114 BOOT_ORDER = 2,
115 POWER_POLICY = 3,
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530116};
117
118struct ctrl_panel
119{
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400120 panel parent;
121 size_t item_num;
122 std::array<std::string, 8> item_str;
123 panel (*select)(size_t item);
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530124};
125
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400126static panel panel_main(size_t item);
127static panel panel_boot_order(size_t item);
128static panel panel_power_policy(size_t item);
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530129
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400130static ctrl_panel panels[] = {
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530131 {/* dummy entry for making other to 1-based */},
132 {
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400133 .parent = panel::MAIN,
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530134 .item_num = 2,
135 .item_str =
136 {
137 "User Setting",
138 ">Boot Order",
139 ">Power Policy",
140 },
141 .select = panel_main,
142 },
143 {
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400144 .parent = panel::MAIN,
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530145 .item_num = 0,
146 .item_str =
147 {
148 "Boot Order",
149 },
150 .select = panel_boot_order,
151 },
152 {
Patrick Williamsa758d0a2024-08-27 08:35:55 -0400153 .parent = panel::MAIN,
Karthikeyan Pasupathi813f2932022-04-06 14:10:48 +0530154 .item_num = 0,
155 .item_str =
156 {
157 "Power Policy",
158 },
159 .select = panel_power_policy,
160 },
161};
162
163} // end of namespace ipmi