blob: 743829b20ea00940a2fa50cd508065ee233ec6b5 [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
17#include <host-ipmid/ipmid-api.h>
18#include <stdbool.h>
19#include <stdio.h>
20#include <sys/stat.h>
21
22#include <appcommands.hpp>
23#include <ipmid/api.hpp>
24#include <nlohmann/json.hpp>
25#include <phosphor-logging/log.hpp>
26#include <sdbusplus/asio/connection.hpp>
27
28#include <fstream>
29#include <iomanip>
30#include <iostream>
31#include <sstream>
32
33namespace ipmi
34{
35
36#define JSON_POST_DATA_FILE "/usr/share/lcd-debug/post_desc.json"
37#define JSON_GPIO_DATA_FILE "/usr/share/lcd-debug/gpio_desc.json"
38#define JSON_SENSOR_NAMES_FILE "/usr/share/lcd-debug/cri_sensors.json"
39
40#define ETH_INTF_NAME "eth0"
41
42#define ESCAPE "\x1B"
43#define ESC_BAT ESCAPE "B"
44#define ESC_MCU_BL_VER ESCAPE "U"
45#define ESC_MCU_RUN_VER ESCAPE "R"
46#define ESC_ALT ESCAPE "[5;7m"
47#define ESC_RST ESCAPE "[m"
48
49#define LINE_DELIMITER '\x1F'
50
51#define FRAME_BUFF_SIZE 4096
52#define FRAME_PAGE_BUF_SIZE 256
53#define FRU_ALL 0
54#define MAX_VALUE_LEN 64
55
56#define DEBUG_GPIO_KEY "GpioDesc"
57#define GPIO_ARRAY_SIZE 4
58#define GPIO_PIN_INDEX 0
59#define GPIO_LEVEL_INDEX 1
60#define GPIO_DEF_INDEX 2
61#define GPIO_DESC_INDEX 3
62#define BMC_POSITION 0
63#define MAX_HOST_POS 4
64
65/* Used for systems which do not specifically have a
66 * phase, and we want to ignore the phase provided by the
67 * debug card */
68#define PHASE_ANY 0xff
69
70static constexpr bool DEBUG = false;
71static const uint8_t meAddress = 1;
72static constexpr uint8_t lun = 0;
73
74using IpmbMethodType =
75 std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>;
76
77typedef struct _sensor_desc
78{
79 char name[16];
80 uint8_t sensor_num;
81 char unit[5];
82 uint8_t fru;
83 uint8_t disp_prec;
84} sensor_desc_t;
85
86struct frame
87{
88 char title[32];
89 size_t max_size;
90 size_t max_page;
91 char* buf;
92 uint16_t idx_head, idx_tail;
93 uint8_t line_per_page;
94 uint8_t line_width;
95 uint16_t lines, pages;
96 uint8_t esc_sts;
97 uint8_t overwrite;
98 time_t mtime;
99 frame() : buf(NULL), pages(0), mtime(0)
100 {}
101 int init(size_t size);
102 int append(const char* string, int indent);
103 int insert(const char* string, int indent);
104 int getPage(int page, char* page_buf, size_t page_buf_size);
105 int isFull();
106 int isEscSeq(char chr);
107 int parse(char* buf, size_t buf_size, const char* input, int indent);
108};
109
110struct frame frame_info;
111struct frame frame_sel;
112struct frame frame_snr;
113
114enum ENUM_PANEL
115{
116 PANEL_MAIN = 1,
117 PANEL_BOOT_ORDER = 2,
118 PANEL_POWER_POLICY = 3,
119};
120
121struct ctrl_panel
122{
123 uint8_t parent;
124 uint8_t item_num;
125 char item_str[8][32];
126 uint8_t (*select)(uint8_t item);
127};
128
129static uint8_t panel_main(uint8_t item);
130static uint8_t panel_boot_order(uint8_t item);
131static uint8_t panel_power_policy(uint8_t item);
132
133static struct ctrl_panel panels[] = {
134 {/* dummy entry for making other to 1-based */},
135 {
136 .parent = PANEL_MAIN,
137 .item_num = 2,
138 .item_str =
139 {
140 "User Setting",
141 ">Boot Order",
142 ">Power Policy",
143 },
144 .select = panel_main,
145 },
146 {
147 .parent = PANEL_MAIN,
148 .item_num = 0,
149 .item_str =
150 {
151 "Boot Order",
152 },
153 .select = panel_boot_order,
154 },
155 {
156 .parent = PANEL_MAIN,
157 .item_num = 0,
158 .item_str =
159 {
160 "Power Policy",
161 },
162 .select = panel_power_policy,
163 },
164};
165
166} // end of namespace ipmi